NSURLConnection不发送数据,但连接

时间:2012-03-01 18:54:45

标签: objective-c nsurlconnection nsmutableurlrequest

URL写得正确,我在浏览器中用数据测试它并且它正确发送,但是当我发出请求时,它返回它成功,但它实际上并没有写入数据。有什么想法吗?

- (void)writeAboutMe:(NSString *)about withIcebreaker:(NSString *)icebreaker 
{
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
NSString *urlString = [NSString stringWithFormat:@"http://nailorbail.net63.net/submit_about_and_icebreaker.php?username=%@&about=%@&icebreaker=%@",[SignInViewController getUsernameString] ,about,icebreaker];
NSLog(@"%@",urlString);
[request setURL:[NSURL URLWithString:urlString]];

[request setHTTPMethod:@"GET"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if(conn)
    NSLog(@"Connection Successful");
else
    NSLog(@"Connection could not be made");
[conn release];
}

2 个答案:

答案 0 :(得分:1)

您已设置异步连接。您是否实现了NSURLConnection委托协议方法?是否有人被召唤?

创建连接实例并没有说明它的成功。

查看一些教程like this one

答案 1 :(得分:1)

这可能是编码问题。 getUsernameStringabouticebreaker中包含哪些字符?正如Maudicus所说,你需要自己处理URL中的特殊字符。

尝试:

urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]