1:初始化 NSURLConnection
[NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:url] delegate:self];
2: 在 didReceiveResponse 委托中获取服务器返回过来的信息
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; NSDictionary *responseHeaders = [httpResponse allHeaderFields]; NSLog(@"didReceiveResponseHeaders = %@",responseHeaders); }
3:在任何时候都可以将connection 撤销对网络的请求和访问
[connection cancel];
4:网络连接成功后会开始下载, 会定时调用这个委托. 里面提供每一段的下载数据
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { NSLog(@"定时会有新的数据进入这个委托"); }