您的位置:首页 > 其它

AFNetWorking无返回数据 Code=-1016

2016-01-26 15:01 169 查看
Printing description of error:
Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse:
0x7f7fa1700070> { URL: http://192.168.10.155:80/WebService/ } { status code: 200, headers {
    Connection = close;
    "Content-Length" = 111;
    "Content-Type" = "text/html; charset=UTF-8";
    Date = "Tue, 26 Jan 2016 06:53:25 GMT";
    Server = "Apache/2.2.15 (CentOS)";
    "X-Powered-By" = "PHP/5.3.3";
} }, NSErrorFailingURLKey=http://192.168.10.155:80/WebService/, com.alamofire.serialization.response.error.data=<7b22746f 6b656e22 3a226163 37333844 4d6d4c50 39505c2f
5a574650 425c2f77 665c2f32 3837636a 39487178 466b385c 2f723655 39364162 4e544f33 4b414c7a 5131416f 67483548 7a6a7556 45725768 6b306668 4d505248 2b506c71 354d4d77 222c2263 6f646522 3a223030 31227d>, NSLocalizedDescription=Request failed: unacceptable content-type:
text/html}

在使用AFNetWorking进行网络请求时,请求不到数据,error的信息显示如上所示。其原因是failed: unacceptable content-type: text/html。

AFNetWorking默认不支持text/html,
AFURLResponseSerialization.m
源码  ->   self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil]; 

那么需要修改一下。

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

over!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  AFNetWorking