• 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一次,不然配置的东西无效。

     

  • 相关阅读:
    Rancher 中 Traefik 负载均衡 Initializing 状态
    【音视频】YUV、RGB视频像素处理
    Debian WSL 2 安装使用 Docker
    CentOS 7 切换 Java 版本到 Java 11
    阿里云 CentOS 8.2 停服后 yum / dnf 无法安装更新
    CentOS 8 Stream 报错处理 Faild to start Load Kernel Modules. Failed to insert 'ipmi_si': No such device
    System.getProperty()获取系统变量
    简单科普私钥、地址、助记词、Keystore的区别
    synchronized实现原理及锁升级过程
    H3C 策略路由原理介绍
  • 原文地址:https://www.cnblogs.com/wangxiaorui/p/5345148.html
Copyright © 2020-2023  润新知