码迷,mamicode.com
首页 > Web开发 > 详细

AFNetworking 不支持 text/plain,unacceptable content-type: text/plain

时间:2015-12-16 15:29:55      阅读:4672      评论:0      收藏:0      [点我收藏+]

标签:

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数据,还是需要自己转成文本格式。

AFNetworking 不支持 text/plain,unacceptable content-type: text/plain

标签:

原文地址:http://www.cnblogs.com/XXxiaotaiyang/p/5051142.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!