iOS—修改AFNetworking源文件可接收text/plain的方法

时间:2021-6-3 作者:qvyue

错误描述:
Error Domain=com.alamofire.error.serialization.response Code=-1016 “Request failed: unacceptable content-type: text/plain” UserInfo={com.alamofire.serialization.response.error.response= { URL: https://dem03-soa-app.duanrong.com/user/getUserDataAnalyse.do?userToken=e8a8431866462c32a49b76a0a3e1d8ba&userId=3URNnunURR3mucnz } { status code: 200, headers {

Connection = “keep-alive”;

“Content-Length” = 44;

“Content-Type” = “text/plain;charset=UTF-8”;

Date = “Wed, 23 Aug 2017 03:35:26 GMT”;

Server = nginx;

“Strict-Transport-Security” = “max-age=31536000; includeSubdomains”;

“X-Content-Security-Policy” = “default-src ‘self’; script-src ‘self’; img-src ‘self'”;

“X-Frame-Options” = SAMEORIGIN;

} }, NSErrorFailingURLKey=https://dem03-soa-app.duanrong.com/user/getUserDataAnalyse.do?userToken=e8a8431866462c32a49b76a0a3e1d8ba&userId=3URNnunURR3mucnz, com.alamofire.serialization.response.error.data=, NSLocalizedDescription=Request failed: unacceptable content-type: text/plain}

这就是打印的错误描述,看描述讲的就是:unacceptable content-type: text/plain,,

就是缺少 text/plain 的接收类型,

在网上查找的些方法,貌似还不能解决问题,后来找了旧项目,找到了解决方法。
只需要前往AFNetworking源代码目录找到AFURLResponseSerialization.m文件将里面的代码:

self.acceptableContentTypes =[NSSetsetWithObjects:@”application/json”,@”text/json”,@”text/JavaScript”,nil];

修改为:

self.acceptableContentTypes= [NSSetsetWithObjects:@”application/json”,@”text/json”,@”text/javascript”,@”text/plain”,@”text/html”,nil];

大功告成!

声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:qvyue@qq.com 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。