zoukankan      html  css  js  c++  java
  • iOS开发网络篇—网络请求(HTTP协议)小结

    iOS开发网络篇—网络请求(HTTP协议)小结

    iOS开发网络篇—网络请求(HTTP协议)小结

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

    2.通信过程

    1> 请求

    * 客户端 --> 服务器

    * 请求的内容

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

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

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

    2> 响应

    * 服务器 --> 客户端

    * 响应的内容

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

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

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

    3.HTTP请求的方法

    1> GET

    * 参数都拼接在URL后面

    * 参数有限制

    2> POST

    * 参数都在请求体

    * 参数没有限制

    4.iOS中发送GETPOST请求的手段

    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];

     
     
    标签: IOS开发网络篇
    绿色通道: 好文要顶 关注我 收藏该文与我联系 
    0
    0
     
    (请您对文章做出评价)
     
  • 相关阅读:
    java-线程
    List、Map、set的加载因子,默认初始容量和扩容增量
    Mybatis使用generator自动生成映射配置文件信息
    Fiddler手机https抓包
    通知消息与ON_NOTIFY
    ATL实现COM组件
    vs参数配置
    QToolBox
    CTreeCtrl控件
    SQL-INSERT INTO用法
  • 原文地址:https://www.cnblogs.com/iOS-mt/p/4172459.html
Copyright © 2011-2022 走看看