标签:
今天使用AFN框架时出现了以下错误提示信息
Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html"
经过百度,发现原来是个普遍问题,是AF2.0本身的问题,解析格式不全,所以需要在AF的源文件AFURLResponseSerialization.m中修改代码就能解决:
修改文件223行处:
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil];
为
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
即可,亲测成功。
但是接受返回数据时又出现了以下错误:
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.)
解决方法是再创建AFHTTPRequestOperationManager对象时添加下面两行代码
1 AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager]; 2 mgr.requestSerializer = [AFHTTPRequestSerializer serializer]; 3 mgr.responseSerializer = [AFHTTPResponseSerializer serializer];
标签:
原文地址:http://www.cnblogs.com/iamjjh/p/4563289.html