找不到NSURL当带有空格参数的URL字符串?

时间:2012-09-27 11:01:23

标签: iphone objective-c nsstring nsurl

我使用了UserName = raj和pwd = space,但该url字符串在NSURL中没有使用。

NSString *urlstr = [NSString stringWithFormat:@"http://www.test.com/data/image/sd.php?Uname=raj&password=Space"];

NSURL *Url =  [NSURL URLWithString:urlstr];

3 个答案:

答案 0 :(得分:0)

试试这个: -

NSString *urlstr = [NSString stringWithFormat:@"http://www.test.com/data/image/sd.php?Uname=raj&password=Space"];
NSURL *url = [[NSURL alloc] initWithString:
[urlstr stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];

答案 1 :(得分:0)

NSURL *url = [NSURL URLWithString:@"http://www.test.com/data/image/sd.php?Uname=raj&password=Space"];

答案 2 :(得分:0)

如果您从textfield获取值,请尝试以下操作:

NSString *urlstr = [NSString stringWithFormat:@"http://www.test.com/data/image/sd.php?Uname=%@&password=%@",[usernameField.text stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding],[passwordField.text stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];