iOS—修改AFNetworking源文件可接收text/pla

2017-08-23  本文已影响99人  山野武夫

错误描述:
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=<7b226572 72636f64 65223a22 34303030 32222c22 6572726d 7367223a 22546f6b 656e2065 78706972 6564227d>, 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];

大功告成!

上一篇下一篇

猜你喜欢

热点阅读