https://blog.csdn.net/ccflying88/article/details/50893639
// 同步请求,一直在等待服务器返回数据; [conn sendSynchronousRequest:request returningResponse:nil error:ni]; 异步请求 <1>.直接发送请求 NSOperationQueue *queue = [[NSOperationQueue alloc] init]; [conn sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response,NSData *data, NSError *error){ // 当请求成功或者遇到请求错误时调用; }]; 异步请求 <2>.通过代理来发送请求 + NSURLConnection *conn = [NSURLConnection connectionWithRequest:request delegate:self]; - (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate startImmediately:(BOOL)immediately; // 如果immediately为NO,则需要再调用[conn start]; // 异步执行; // 实现代理对象4个常用方法 -(void)connection: didFailWithError: // 请求错误(失败)时调用(超时,断网,客户端错误); -(void)connection: didReceiveResponse: // 当接收到服务器的响应就会被调用; -(void)connection: didReceiveData: // 当接收到服务器的数据时调用(可能会多次调用); -(void)connectionDidFinishLoading: // 服务器的数据接收完毕;