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

下面是错误信息:

获取服务器响应出错 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. NHibernate Demo 和 效率测试

    本文关于NHibernate的Demo和效率测试,希望对大家有用. 1.先去官网下载Nhibernate 2.放入到项目中并建立Helper类 private static ISession _Ses ...

  2. C#矩阵运算类库

    这个类库是本人参考许多相关资料之后做出的C#矩阵运算类库,因为C#的数值计算库相对比较少,所以希望这个类库能够给大家带来一些帮助. 源码github网址:https://github.com/Josh ...

  3. js加解密

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. Could not find com.android.tools.build:gradle:1.3.0.

    * What went wrong:          A problem occurred configuring project ':TZYJ_Android'.> Could not re ...

  5. mint安装相关数据库lib

    sudo apt-get install libmysqlclient-dev sudo apt-get install sqlite3 libsqlite3-dev

  6. Django 之 ForeignKey、ManyToMany的访问方式

    1.ForeignKey 情况I: from django.db import models class Blog(models.Model): pass class Entry(models.Mod ...

  7. owncloud7.0.2.1升级8.0.3

    进入更新中心升级,会自动备份下载安装,安装完提示更新数据库,跳转页面后提示需要php5.4以上版本,检查当前环境为php5.3.3.服务器为CentOS6.4,使用yum更新最新版本即5.3.3.   ...

  8. LeetCode 371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  9. Solr部署到Tomcat

    1.版本选择 solr-5.3.1.tgz apache-tomcat-8.0.29.tar.gz 2.解压tomcat和solr [root@iZ23exixsjaZ solr]# .tar.gz ...

  10. selenium 介绍1

    本文主要是吸收这些帖子的营养,多谢互联网,和未知名作者. http://www.ltesting.net/ceshi/open/kygncsgj/selenium/2011/1009/203318.h ...