zoukankan      html  css  js  c++  java
  • ISO中AFN的使用步骤

    1.依赖的框架

    * MobileCoreServices.framework

    * SystemConfiguration.framework

    * Security.framework

    2.主头文件:AFNetworking.h

    3.创建POST请求对象

    // BaseURL是基准路径,格式为-> 协议头://主机名,不能包含其他路径

    AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"https://api.weibo.com"]];

    // Method是请求方法

    // path是拼接在基准路径后面的请求路径

    // parametersPOST请求的参数

    NSURLRequest *post = [client requestWithMethod:@"POST" path:@"oauth2/access_token" parameters:@{

                          @"client_id" : kAppKey,

                          @"client_secret" : kAppSecret,

                          @"grant_type" : @"authorization_code",

                          @"redirect_uri" : kRedirectURI,

                          @"code" : requestToken

    }];

    4.发送请求,解析服务器的JSON数据

    // 创建操作对象

    NSOperation *op = [AFJSONRequestOperation JSONRequestOperationWithRequest:post

    success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {

        // AFN认为请求成功会调用

    }

    failure : ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {

        // AFN认为请求失败会调用

    }];

    // 执行操作

    [op start];

    5.AFJSONRequestOperation默认不接收text/plain类型的数据,当服务器返回text/plain类型的数据时,会认为出错了。可以通过修改源代码解决问题

    * 修改AFJSONRequestOperation的下列方法

    + (NSSet *)acceptableContentTypes {

        return [NSSet setWithObjects:@"text/plain", @"application/json", @"text/json", @"text/javascript", nil];

    }

  • 相关阅读:
    Node+OBS直播服务器搭建总结
    WebRTC网页录制音视频教程
    人生有尺 做人有度
    「道 德 經」 : 第 二 十 四 章
    看山是山,看水是水;看山不是山,看水不是水;看山还是山,看水还是水。
    「道 德 经」 : 第 八 章
    Ubuntu下安装Chrome浏览器的两个方法
    chromium中增加自己的文件夹
    chromium 切换主分支的方法
    chromium 示例
  • 原文地址:https://www.cnblogs.com/changxs/p/3440491.html
Copyright © 2011-2022 走看看