AFN不支持 "text/html" 的数据的问题:unacceptable content-type: text/html
使用AFN若遇到这个错误信息
Request failed: unacceptable content-type: text/html
bug原因:
这不是AFNetworking的问题
这是做Server那边的人沒把head内的 meta的content格式指定好
解决方法: 本文介绍两种方法, 第一种方法较好, 第二种存在风险, 特此说明,请勿使用第二种!
1.第一种方法:
在懒加载AFHTTPSessionManager 对象时, 告诉AFN,支持接受 text/xml 的数据,代码如下:
- (AFHTTPSessionManager *)mgr{
if (_mgr == nil) {
_mgr = [AFHTTPSessionManager manager];
// 告诉AFN,支持接受 text/xml 的数据
_mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
}
return _mgr;
}
2.第二种方法: (强烈不建议使用)
修改AFN框架, 找到框架的init方法:
- (instancetype)init {
self = [super init];
if (!self) {
return nil;
}
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
return self;
}
在该方法中添加类型。
不建议使用的原因是:只是修改了这个程序的AFN框架, 当框架升级或者上传代码到仓库, 再下载的时候,还是要改AFN框架, 太麻烦!
找init的路径:Pods/AFNetworking/Serialization/AFURLResponseSerialization.m 下的init方法
AFN不支持 "text/html" 的数据的问题:unacceptable content-type: text/html的更多相关文章
- AFNetworking request failed unacceptable content type text/html
今天体验AFNetwork 3.1.0 进行数据解析,但是解析数据控制台一直都输出这样的 error 结果: 于是,照着以前AFN2.+版本的进行设置: 结果发现在新版本的 AFN 上不能设置了.既然 ...
- 遇到问题之“postman报Unsupported Media Type: Content type 'text/plain;charset=UTF-8' not supported”
postman报Unsupported Media Type: Content type 'text/plain;charset=UTF-8' not supported postman之所以报Uns ...
- {"timestamp":"2019-11-12T02:39:28.949+0000","status":415,"error":"Unsupported Media Type","message":"Content type 'text/plain;charset=UTF-8' not supported","path":&quo
在Jmeter运行http请求时报错: {"timestamp":"2019-11-12T02:39:28.949+0000","status&quo ...
- IE支持直接查看Json数据注册表代码
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/json] ...
- input type =text,按回车键自动提交
1.当form表单中只有一个<input type="text" name='name' />时按回车键将会自动将表单提交 <form id='form1' ac ...
- No handler for type [text] declared on field [content]
Install 1.compile checkout ik version respective to your elasticsearch version git checkout tags/{ve ...
- HTML:<input type="text"> 输入数字时的验证!(在提交时验证)
<!--非负数:<input type="text" name="" pattern="^\d+$">--> < ...
- CYQ.Data 支持WPF相关的数据控件绑定.Net获取iis版本
CYQ.Data 支持WPF相关的数据控件绑定(2013-08-09) 事件的结果 经过多天的思考及忙碌的开发及测试,CYQ.Data 终于在UI上全面支持WPF,至此,CYQ.Data 已经可以方便 ...
- Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.
用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不符合要求. 请求代码如下: private static ...
随机推荐
- Codeforces 525A - Vitaliy and Pie
525A - Vitaliy and Pie 思路:贪心+hashing. 代码: #include<bits/stdc++.h> using namespace std; string ...
- 4-6 select_tag和select的区别和理解。javascript_tag
via: :all是什么意思?主要用于约束http动作. <%= select_tag "set_locale", options_for_select(LANGUAGES, ...
- robot framework学习笔记2
声明:本笔记都只是自己根据大牛虫师的robot系列文档学习记录的,学习的话还请移步虫师博客:https://www.cnblogs.com/fnng/ 非常感谢大牛的分享,带小白一步一步入门 F5 ...
- Non-parseable POM 解决方法
两个build放在一起当然不行,把它们类似这样的合并起来.
- 微信公众号开发之如何一键导出微信所有用户信息到Excel
微信开发交流群:148540125 系列文章参考地址 极速开发微信公众号欢迎留言.转发.打赏 项目源码参考地址 点我点我--欢迎Start 极速开发微信公众号系列文章之如何一键导出微信所有用户信息到E ...
- Leetcode 86
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode ...
- 4.1 delegate
delegate ---packed up function public delegate double myDelegate (double x); my delegate d2 = new m ...
- 使用简单的python语句编写爬虫 定时拿取信息并存入txt
# -*- coding: utf-8 -*- #解决编码问题import urllibimport urllib2import reimport osimport time page = 1url ...
- codeforce 853A Planning
题目地址:http://codeforces.com/problemset/problem/853/A 题目大意: 本来安排了 n 架飞机,每架飞机有 ci 的重要度, 第 i 架飞机的起飞时间为 i ...
- RM报表 实际打印的判断
procedure TFormDZMD.RMReport1PrintReportEvent(Sender: TObject); begin // Log('RMReport1PrintReportEv ...