zoukankan      html  css  js  c++  java
  • AFNetWorking发送post请求,Code=-1016错误

      使用AFNetWorking发送post请求时,可能会出现下面Code=-1016问题。打印的error如下:

    Error:Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo=0x7fba3b6f1ba0 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fba3d8822c0> { URL: http://www.joinbuy.cn/api/login.ios.php?token=15x4874otutDRYxofue8&act=login } { status code: 200, headers {
    Pragma = no-cache,
    X-Powered-By = PHP/5.2.17,
    Server = Apache/2.2.24 (Unix) PHP/5.2.17,
    Set-Cookie = deal_city=deleted; expires=Sun, 07-Sep-2014 08:28:41 GMT; path=/api/,
    Keep-Alive = timeout=5, max=100,
    Connection = Keep-Alive,
    Date = Mon, 07 Sep 2015 08:28:42 GMT,
    Content-Type = text/html; charset=utf-8,
    Content-Length = 46,
    Expires = Thu, 19 Nov 1981 08:52:00 GMT,
    Cache-Control = no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    } }, NSErrorFailingURLKey=http://www.joinbuy.cn/api/login.ios.php?token=15x4874otutDRYxofue8&act=login, com.alamofire.serialization.response.error.data=<7b226d73 67223a22 5c753864 32365c75 35336637 5c753562 63365c75 37383031 5c753935 31395c75 38626566 227d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}

      AFNetWorking的JSON解析默认库是使用的AFJSONRequestOperation模式,只支持text/json,application/json,text/javascript,所以如果出现code=-1016错误则说明当前的JSON解析模式是text/html,所以要加上这段代码:
    [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];

    或者

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

    让他支持text/html模式就可以解决了

  • 相关阅读:
    [蓝桥杯][算法提高VIP]传染病控制
    PAT甲级第二次真题练习
    BFS()搜索加上hash
    PAT甲级第一次真题练习
    一个小练习题
    八皇后
    【Noi 1994 删数问题】【openjudge 3528 最小新整数(变式)】整型与字符
    【openjudge 2469 电池的寿命】算法与思维
    MarkDown测试
    HNOI 2017 怼大佬
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/4789269.html
Copyright © 2011-2022 走看看