NSURLConnection

简介: 1:初始化 NSURLConnection [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:url] delegate:self];2: 在 didR...

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(@"定时会有新的数据进入这个委托");
}


目录
相关文章
|
7月前
|
iOS开发
iOS开发 GET、POST请求方法:NSURLSession篇
iOS开发 GET、POST请求方法:NSURLSession篇
74 0
|
程序员 iOS开发
NSNotification、Delegate、Block和KVO的区别是什么
NSNotification、Delegate、Block和KVO的区别是什么
101 0
UIActionSheet,UIAlertView,UIAlertController的详细说明
UIActionSheet,UIAlertView,UIAlertController的详细说明
98 0
UIActionSheet,UIAlertView,UIAlertController的详细说明
NSURLConnection
简介 常用类 NSURL:请求地址; NSURLRequest:一个 NSURLRequest 对象就代表一个请求,它包含的信息有:一个 NSURL 对象、请求方法、请求头、请求体... NSMutableURLRequest:是 NSURLRequest 的子类; NSURLConnection:负责发送请求,建立客户端和服务器的连接。
913 0
|
Android开发 iOS开发 JavaScript
WKWebView代理方法解析
一.前言 上一篇文章已经对WKWebView做了一个简单的介绍,主要对它的一些方法和属性做了一个简单的介绍,今天看一下WKWebView的两个协议:WKNavigationDelegate 和 WKUIDelegate。
3184 0
|
XML JSON iOS开发
iOS - NSURLConnection 网络请求
前言 @interface NSURLConnection : NSObject class NSURLConnection : NSObject DEPRECATED: The NSURLConnection class should no longer be used. NSURLSession is the replacement for NSURLConnection 从 iOS 9 开始 NSURLConnection 的大部分方法被废弃。
925 0