码迷,mamicode.com
首页 > 移动开发 > 详细

iOS"Request failed: unacceptable content-type: text/html"

时间:2015-01-19 09:19:01      阅读:1188      评论:0      收藏:0      [点我收藏+]

标签:

以前用的好端端的接口,今天访问居然出错了,但是再用浏览器测试,发现可以正常返回数据,甚是奇怪啊。

下面是错误信息:

获取服务器响应出错 error=ErrorDomain=com.alamofire.error.serialization.response Code=-1016"Request failed: unacceptable content-type: text/html"UserInfo=0x7fdfd8729680{com.alamofire.serialization.response.error.response= { URL:http://172.16.1.31:7001/itom/getwork } { status code: 200, headers{

   "Cache-Control" = "no-cache";

   "Content-Type" = "text/html;charset=UTF-8";

    Date= "Mon, 24 Nov 2014 03:13:16 GMT";

   "Transfer-Encoding" = Identity;

   "X-Powered-By" = "Servlet/2.5 JSP/2.1";

} },NSErrorFailingURLKey=http://172.16.1.31:7001/itom/getwork,com.alamofire.serialization.response.error.data=<5b7b227374617475 73223a22 73756363 65737322 2c226d73 67223a22 e799bbe99986e688 90e58a9f 227d5d>, NSLocalizedDescription=Requestfailed: unacceptable content-type: text/html}


下面是百度出来的答案:

I also encountered the same problem.This means that your server issending "text/html" insteadof the already supported types. After a little search, my solutionwas toadd "text/html" to acceptableContentTypes setin AFURLResponseSerialization class.Just search for "acceptableContentTypes" andadd @"text/html" tothe set manually. Of course, the ideal solution will be to changethe tpe from the server, but for that you will hade to talk withthe server team.

I hope this helps you. Best regards andless bugs as possible in the code.

 op.responseSerializer.acceptableContentTypes =[NSSet setWithObject:@"text/html”];


对应到自己的项目里面,我用的是AFNetworking这套网络请求包,需要改的是:

AFURLResponseSerialization.m文件

223行:

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

加上蓝色部分,其实就是添加一种服务器返回的数据格式。


也可以看看这个参考

http://www.isaced.com/post-254.html

iOS"Request failed: unacceptable content-type: text/html"

标签:

原文地址:http://blog.csdn.net/rainshenji/article/details/42847571

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!