开发者

NSURL doesn't seem to want to accept my querystring

开发者 https://www.devze.com 2023-01-14 12:02 出处:网络
Hi there I have this code NSLog(@\"%@\",URLRequestQueryString); NSString *sendToServerString = [NSString stringWithFormat:@\"http://mydomain.co.uk/req.php%@\",URLRequestQueryString];

Hi there I have this code

NSLog(@"%@",URLRequestQueryString);
NSString *sendToServerString = [NSString stringWithFormat:@"http://mydomain.co.uk/req.php%@",URLRequestQueryString];
NSURL *sendToServer = [[NSURL alloc] initWithString:sendToServerString];
NSLog(@"%@",sendToServer);
NSLog(@"%@",sendToServerString);

URLRequestQueryString is just a standard querystring that I have built up throughout the script.

The first NSLog works fine and outputs a proper querystring (if I copy and paste it into a browser then the page will load and run correctly.

This is also the case wh开发者_StackOverflowen I output sendToServerString it correctly outputs the URL with querystring (which I can also copy and paste into a browser).

However sendToServer ouputs (null). If I remove the querystring it will correctly output the domain and path.

Any idea why this happens? How can I sort it?

Thank you.


NSURL *sendToServer = [NSURL URLWithString: [sendToServerString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
Could be what you are looking for. :)


You need see NSString reference. A Section named "Working with URLs". Under this section has two method

  • stringByAddingPercentEscapesUsingEncoding:
  • stringByReplacingPercentEscapesUsingEncoding:
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号