0

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];
}
4

2 回答 2

1

您已经建立了一个异步连接。你实现了 NSURLConnection 委托协议方法吗?他们中的任何一个都被调用了吗?

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

查看一些教程,比如这个

于 2012-03-01T19:10:32.650 回答
1

可能是编码问题。getUsernameStringabout和中有哪些类型的字符icebreaker?正如 Maudicus 所提到的,您需要自己处理 URL 中的特殊字符。

尝试:

urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
于 2012-03-01T19:25:21.660 回答