这是我需要发布http://www.mysite.com/save?details= {“name”}
的字符串我尝试以下代码;
NSString * post = [NSString stringWithFormat:@“details = {\”name \“}”];
NSString *hostStr = @"http://www.mysite.com/save?";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
但serverOutput总是= null,除非我只是{name}。但我需要那里的qutoes :(
答案 0 :(得分:0)
您应该将所有内容转换为有效的HTTP符号。
e.g:
hostStr = [hostStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
...我的猜测是您的网络服务器拒绝无效网址。
答案 1 :(得分:0)
错误..
NSString * post = [NSString stringWithFormat:@“details = {\”name \“}”];
<强>正确:强>
NSString * post = [NSString stringWithString:@“details = {\”name \“}”];