zoukankan      html  css  js  c++  java
  • 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];

     
  • 相关阅读:
    二叉树
    基础1
    tcp/udp
    异步io模块(自定义)
    select+异步
    异步发送请求的几种方式
    多线程,进程实现并发请求
    位解包运算
    从前端程序员的视角看小程序的稳定性保障
    运行node 报错 throw er; // Unhandled 'error' event
  • 原文地址:https://www.cnblogs.com/gegeboke/p/4329291.html
Copyright © 2011-2022 走看看