接口访问出错了,用浏览器测试,发现可以正常返回数据.

下面是错误信息:

获取服务器响应出错 error=Error Domain=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=<5b7b2273 74617475 73223a22 73756363 65737322 2c226d73 67223a22 e799bbe9 9986e688 90e58a9f 227d5d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}


下面是百度出来的答案:

I also encountered the same problem.
This means that your server is
sending "text/html" instead
of the already supported types. After a little search, my solution
was to
add "text/html" to acceptableContentTypes set
in AFURLResponseSerialization class.
Just search for "acceptableContentTypes" and
add @"text/html" to
the set manually. Of course, the ideal solution will be to change
the tpe from the server, but for that you will hade to talk with
the server team.

I hope this helps you. Best regards and
less 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];

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

iOS"Request failed: unacceptable content-type: text/html"的更多相关文章

  1. AFNetworking request failed unacceptable content type text/html

    今天体验AFNetwork 3.1.0 进行数据解析,但是解析数据控制台一直都输出这样的 error 结果: 于是,照着以前AFN2.+版本的进行设置: 结果发现在新版本的 AFN 上不能设置了.既然 ...

  2. iOS 使用AFNetworking遇到错误 Request failed: unacceptable content-type: text/html

    错误日志: Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacc ...

  3. iOS AFNetworking “Request failed: unacceptable content-type: text/html”问题

    使用AFNetworking出现报错: error=Error Domain=com.alamofire.error.serialization.response Code=-1016 "R ...

  4. iOS 使用AFNetworking遇到异常 Request failed: unacceptable content-type: text/html

    错误日志是: Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unac ...

  5. AFNetworking遇到错误 Request failed: unacceptable content-type: text/html

    iOS 使用AFNetworking遇到错误 Request failed: unacceptable content-type: text/html 原因: 不可接受的内容类型 “text/html ...

  6. 使用AFNetworking 2.0 请求数据时出现错误 Request failed: unacceptable content-type: text/html 解决方法

    使用AFNetworking 2.0 请求数据时出现错误 Request failed: unacceptable content-type: text/html 解决方法 添加一行 manager. ...

  7. Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html"

    2015-11-16 10:39:17.235 PullDemo[338:60b] Application windows are expected to have a root view contr ...

  8. AFNetworking 遇到错误 Code=-1016 "Request failed: unacceptable content-type: text/plain"

    在开发过程使用了AFNetworking库,版本2.x,先运行第一个官方例子(替换GET 后面的url即可): AFHTTPRequestOperationManager *manager = [AF ...

  9. NSLocalizedDescription=Request failed: unacceptable content-type: text/html 解决方法

    使用AFNetworking请求一个网站出现了以下错误 Error Domain=com.alamofire.error.serialization.response Code=- "Req ...

随机推荐

  1. spring mvc 删除返回字符串中值为null的字段

    在spring的配置文件中进行一下配置: <bean class="org.springframework.web.servlet.mvc.method.annotation.Requ ...

  2. LAN-LAN FREE-SERVER FREE

    注:本文转自http://taotao1240.blog.51cto.com/731446/839702 CU上有个板块叫“存储备份”,可见存储和备份是紧紧联系的.在看备份的时候,经常能看到LAN f ...

  3. 别人整理的DP大全(转)

    动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...

  4. C++ 实现Range类,用于常规遍历

    PYTHON的Range类非常好用,所以用C++来简单实现下:  // 实现Range类,用于遍历 // #include <string> class Range { public: / ...

  5. Windows消息过滤

    在C#编程中,经常会遇到一些场景,如禁止鼠标拖动窗体,启用某些快捷键,禁止鼠标移动等.遇到这些需求,可以通过窗体的MouseMove事件,OnDragDrop,OnMove等事件来解决问题, 但是该方 ...

  6. FPGA综合工具--Synplify Pro的常用选项及命令

    最近要用到Synplify,但以前没使用过,无基础,找到一篇帖子,隧保存下来. 本文转自:http://blog.sina.com.cn/s/blog_65fe490d0100v8ax.html Sy ...

  7. 重置zend studio 默认设置的方法

    转载自:http://www.zendstudio.net/archives/reset-the-zend-studio-settings/ 这个方法类似于手机的"恢复出厂设置"的 ...

  8. ARCGIS多种影像裁剪

    在互联网上下载的遥感影像都进行过分幅处理,下载下来的影像多是规则的四方形,而在进行遥感影像研究时,多是针对特定区域来进行,比如研究北京市的遥感影像,不在北京市范围内的影像对于研究者就没有利用意义,如果 ...

  9. IS A 和 HAS A的区别

    IS A:一般是用作继承或者接口类.比如:中国人和外国人都是人,重点在:是一个... . HAS A:一般用作对象和他的成员的从属关系.比如:中国人和外国人都有眼睛.耳朵.嘴巴.重点在:有一个... ...

  10. Java三大框架的配置

    1. 首先是spring,右键项目-myeclipse-capabilitise-install spring etc.类似的就好,生成applicationContext.xml和spring一些类 ...