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

    今天在做上传图片的时候,突然总是报错,用client或者postman是正常的,看了下报错信息

    2015-09-16 14:19:37.665 kuaixiu-vendor[12897:2996954] error:Error Domain=com.alamofire.error.serialization.response Code=-1016 “Request failed: unacceptable content-type: text/html” UserInfo=0x1702e1700 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x174235540> { URL: http://192.168.1.31/kuaixiu/web/app_dev.php/apishop/upload } { status code: 200, headers {

        “Cache-Control” = “no-cache”;

        Connection = “Keep-Alive”;

        “Content-Encoding” = gzip;

        “Content-Type” = “text/html; charset=UTF-8”;

        Date = “Wed, 16 Sep 2015 06:19:33 GMT”;

        “Keep-Alive” = “timeout=5, max=100”;

        Server = “Apache/2.4.7 (Ubuntu)”;

        “Transfer-Encoding” = Identity;

        Vary = “Accept-Encoding”;

        “X-Debug-Token” = 3b15f2;

        “X-Powered-By” = “PHP/5.5.9-1ubuntu4.11”;

    } }, NSErrorFailingURLKey=http://192.168.1.31/kuaixiu/web/app_dev.php/apishop/upload, com.alamofire.serialization.response.error.data=<7b22636f 6465223a 312c226d 65737361 6765223a 225c7534 6530615c 75346632 305c7536 3231305c 75353239 665c7566 66303122 2c226461 7461223a 22353566 39303966 35633636 35632e6a 7067227d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}

    仔细看下报错信息,大致意思就是在接收数据的时候缺少“text/html”这个内容类型。

    解决办法就是在AFNetWorking的responseSerializer里面增加”text/html“这个内容类型。

    1
    2
    3
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFJSONResponseSerializer new];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html"nil];

    这样就大功告成了~但是一定要注意,responseSerializer使用之前一定要new一次,不然配置的东西无效。

     

  • 相关阅读:
    vc枚举本机端口信息API
    xmpp 与服务器连接并身份验证成功
    xmpp 常见错误 一
    xmpp 环境配置
    使用宏定义创建单例
    iOS知识列表
    ios sqlite 简单使用
    关于游戏
    开通博客园博客的第一天
    如何让移动设备的宽与浏览器视图的宽保持一致
  • 原文地址:https://www.cnblogs.com/wangxiaorui/p/5345148.html
Copyright © 2011-2022 走看看