【发布时间】:2011-08-12 19:56:15
【问题描述】:
我正在尝试创建一个简单的 NSURLConnection 以使用 GET 请求与服务器进行通信。 Connection 运行良好,但从未调用 NSURLConnection 的委托方法..
这是在做什么:
NSString *post = [NSString stringWithFormat:@"key1=%@&key2=%@&key3=%f&key4=%@", val1, val4, val3, val4];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease] ;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.domain.com/demo/name/file.php?%@", post]]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
已经实现了以下委托方法,但是没有一个被调用..
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(@"did fail");
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
NSLog(@"did receive data");
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSLog(@"did receive response ");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"did finish loading");
[connection release];
}
我错过了什么吗?
【问题讨论】:
-
你连接到互联网了吗??
-
您能否验证此时您的所有变量都不是 nil (无论出于何种原因)?
-
检查变量
connection的值,因为它可能由于某种原因具有 nil 值。
标签: iphone nsurlconnection nsurlprotocol