您的位置:首页 > 理论基础 > 计算机网络

IOS开发--网络篇-->网络请求(HTTP协议)小结

2015-03-11 11:00 316 查看
IOS开发网络篇—网络请求(HTTP协议)小结

1. 聊一下HTTP协议(协议的完整的通信过程)

2.通信过程

1> 请求

* 客户端 --> 服务器

* 请求的内容

a. 请求行(请求方法\HTTP协议\请求资源路径)

b. 请求头(描述客户端的信息)

c. 请求体(POST请求才需要有, 存放具体数据)

2> 响应

* 服务器 --> 客户端

* 响应的内容

a. 状态行(响应行, 状态码)

b. 响应头(服务器信息, 返回数据的类型, 返回数据的长度)

c. 实体内容(响应体, 返回给客户端的具体内容)

3.HTTP请求的方法

1> GET

* 参数都拼接在URL后面

* 参数有限制

2> POST

* 参数都在请求体

* 参数没有限制

4.iOS中发送GET\POST请求的手段

1> NSURLConnection

* 发送一个同步请求

+ (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error;

* 发送一个异步请求

+ (void)sendAsynchronousRequest:(NSURLRequest*) request

queue:(NSOperationQueue*) queue

completionHandler:(void (^)(NSURLResponse* response, NSData* data, NSError* connectionError)) handler;

* 代理的方法(异步)

[NSURLConnection connectionWithRequest:request delegate:self];

[[NSURLConnection alloc] initWithRequest:request delegate:self];

[[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];

[conn start];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: