AFNetworking 不支持 text/plain,unacceptable content-type: text/plain
时间:2015-12-16 15:29:55
收藏:0
阅读:4672
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数据,还是需要自己转成文本格式。
评论(0)