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模式就可以解决了

 

转载于:https://www.cnblogs.com/yyt-hehe-yyt/p/4789269.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值