zoukankan      html  css  js  c++  java
  • iOS"Request failed: unacceptable content-type: text/html"

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

    下面是错误信息:

    获取服务器响应出错 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];

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

  • 相关阅读:
    Win Server 2008 R2 一键配置全环境 PHP5+MYSQL5+ZEND+PHPMYADMIN
    服务器加固,安全狗V4.0正式版 (Windows)
    Win server 2008 R2激活工具使用图文教程(SK Patch v1 R2 Final OEM)
    Laoy8 V4.0 营销插件
    OK3W发布插件
    流量精灵(P2P方式,刷真实流量)
    aspcms2发布插件
    今天写一篇技术文章,关于TemplateEngine的。
    全面分析新浪博客的登录过程
    网站克隆插件
  • 原文地址:https://www.cnblogs.com/wanggang550/p/5390130.html
Copyright © 2011-2022 走看看