我正在尝试创建一个简单的 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];
}
我错过了什么吗?