zoukankan      html  css  js  c++  java
  • AFNetworking 不支持 text/plain,unacceptable content-type: text/plain

    1、 用AFNetworkingPOST传递参数(获取微博的accessToken)的时候,具体代码如下:

    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
        NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
        parameters[@"client_id"] = @"3113926977";
        parameters[@"client_secret"] = @"09c7301ac169533b1f2440a018e6ce93";
        parameters[@"grant_type"] = @"authorization_code";
        parameters[@"code"] = code;
        parameters[@"redirect_uri"] = @"http://www.baidu.com";
        
        [session POST:@"https://api.weibo.com/oauth2/access_token" parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSLog(@"%@", responseObject);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            NSLog(@"%@",error);
        }];

    报,警告:"Request failed: unacceptable content-type: text/plain"


    百度出来说AFNetworking不支持text/plain,这个格式。

    解决办法1.:在头文件"AFURLResponseSerialization.m"的如下地方添加text/plain就行了。问题解决。

    self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/plain",@"text/json", @"text/javascript", nil];

     解决办法2.添加一句代码:

    session.responseSerializer = [[AFCompoundResponseSerializer alloc] init];

    问题也能解决,但是这样返回的的data数据,还是需要自己转成需要的格式。

  • 相关阅读:
    100 numpy exercises
    IndentationError: unindent does not match any outer indentation level
    Git详解之七:自定义Git
    Git详解之六:Git工具
    Git详解之五:分布式Git
    Git详解之四:服务器上的Git
    Git详解之三:Git分支
    Git详解之二:Git基础
    Git详解之一:Git起步
    Jquery基础之事件操作
  • 原文地址:https://www.cnblogs.com/XXxiaotaiyang/p/5051142.html
Copyright © 2011-2022 走看看