iOS—修改AFNetworking源文件可接收text/plain的方法
来源:互联网 发布:淘宝的延长收货是什么 编辑:程序博客网 时间:2024/05/22 07:03
在使用AFNetworking的时候可能会碰到下面的错误:
{ status code: 200, headers {
"Content-Length" = 14;
"Content-Type" = "text/plain;charset=utf-8";
Date = "Thu, 22 May 2014 10:37:50 GMT";
Server = "Apache-Coyote/1.1";
"Set-Cookie" ="JSESSIONID=C0DFED60A154557F8386E62AB2A066CE; Path=/FHJRDT";
} }, NSLocalizedDescription=Request failed:unacceptable content-type: text/plain}
此时需要修改AFNetworking可接收的Content-Type,前往AFNetworking源代码目录找到AFURLResponseSerialization.m文件将里面的代码:
self.acceptableContentTypes =[NSSetsetWithObjects:@"application/json",@"text/json",@"text/javascript",nil];
修改为:
self.acceptableContentTypes =[NSSetsetWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/html",nil];
-----------------------分界线-----------------------------
以上方法虽然可以实现,但以本人最近的只是来看实在是下下策。
更好的办法是这样:
遇到这个问题的人很有可能是代码中没有添加一段话:manager.responseSerializer = [AFHTTPResponseSerializer serializer];
示例代码如下:
NSString *urlStr =@"http://xxxx";
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer]; //很重要,去掉就容易遇到错误,暂时还未了解更加详细的原因
[manager GET:urlStr parameters:@{@"username":@"xxx",@"password":@"xxx"}success:^(AFHTTPRequestOperation *operation,idresponseObject) {
// 解析成功
NSLog(@"JSON: %@", responseObject);
}failure:^(AFHTTPRequestOperation *operation,NSError *error) {
// 解析失败
NSLog(@"error:++++%@",error.localizedDescription);
}];}
- iOS修改AFNetworking源文件可接收text/plain的方法
- iOS—修改AFNetworking源文件可接收text/plain的方法
- iOS—修改AFNetworking源文件可接收text/plain的方法
- iOS—修改AFNetworking源文件可接收text/plain的方法
- iOS—修改AFNetworking源文件可接收text/plain的方法
- iOS—修改AFNetworking源文件可接收text/plain的方法
- iOS—修改AFNetworking源文件可接收text/plain的方法
- iOS—修改AFNetworking源文件可接收text/plain的方法
- iOS—修改AFNetworking源文件可接收text/plain的方法
- iOS—修改AFNetworking源文件可接收text/plain的方法
- iOS中,修改AFNetworking源文件可接收text/plain的方法"Request failed: unacceptable content-type: text/plain"
- 问题— 修改AFNetworking源文件可接收text/plain的方法
- 修改AFNetworking源文件可接收text/plain和text/html的方法
- iOS—修改AFNetworking源文件可接收text/html的方法
- iOS—修改AFNetworking源文件可接收text/html的方法
- AFNetWorking请求@"text/plain"类型的时候崩溃
- iOS 9 Afnetworking 3.0 Request failed: unacceptable content-type: text/plain
- AFNetworking 错误 Request failed: unacceptable content-type: text/plain
- 【原】如何阅读学术论文
- 大型网站架构之系列
- libevent学习笔记一:总体把握
- 计算机计算乘除法的原理
- springMVC --DispatcherServlet详解
- iOS—修改AFNetworking源文件可接收text/plain的方法
- 树莓派 raspberry安全关机命令重启命令
- AppStore App申请审核加速
- MFC右键弹出菜单,并添加响应函数
- IOS- 得到系统版本
- 机器学习算法需要注意的一些问题
- Jquery中获取iframe的代码(window.top.parent)
- fmt标签
- [iOS]调用layoutSubViews方法(有的时候为啥会调用2遍)