首页 > Web开发 > 详细

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

时间:2015-12-16 15:29:40      阅读:394      评论: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)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!