解决AFNetWorking 请求数据报”Request failed: unacceptable content-type: text/plain” 错误

时间:2021-12-03 10:56:37

大家都说IOS网络请求用第三方库AFNetWorking比较靠谱,结果我根据github的例子试了下发现一来就报错了,首先App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Te……,网上查了下发现原来要在info.plist中添加一个item,如图:

解决AFNetWorking 请求数据报”Request failed: unacceptable content-type: text/plain” 错误


App Transport Security Settings ,类型为Dictionary, 子item    Allow Arbitrary Loads,类型为Boolean,设置为YES。

然后第一个错误就解决了,接下来解决“Request failed: unacceptable content-type: text/plain”,

有2个方法:

一、

AFNAFURLResponseSerialization.m文件中,修改init方法中。

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

中添加@text/plain 就好了

二、

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
好了, 有可以愉快的玩耍了 解决AFNetWorking 请求数据报”Request failed: unacceptable content-type: text/plain” 错误