需要帮助从文本字段条目中替换我的空格以发布到GET
我目前的代码:
NSString* urlString = [NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", messageBox.text];
NSURL *add = [NSURL URLWithString:urlString];
[messageView loadRequest:[NSURLRequest requestWithURL:add]];
但是我试过了
NSString *finalAdd = [add stringByReplacingOccurrencesOfString:@" " withString:@"+"];
答案 0 :(得分:1)
您应该转义参数
NSString* urlString = [NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", [messageBox.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *add = [NSURL URLWithString:urlString];
答案 1 :(得分:0)
结帐this post或this SO question。两者都为编码网址提供了很好的解决方案。