NSLocalizedDescription=Request failed: unacceptable content-type: text/html
今天在做上传图片的时候,突然总是报错,用client或者postman是正常的,看了下报错信息
2015-09-16 14:19:37.665 kuaixiu-vendor[12897:2996954] error:Error Domain=com.alamofire.error.serialization.response Code=-1016 “Request failed: unacceptable content-type: text/html” UserInfo=0x1702e1700 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x174235540> { URL: http://192.168.1.31/kuaixiu/web/app_dev.php/apishop/upload } { status code: 200, headers {
“Cache-Control” = “no-cache”;
Connection = “Keep-Alive”;
“Content-Encoding” = gzip;
“Content-Type” = “text/html; charset=UTF-8”;
Date = “Wed, 16 Sep 2015 06:19:33 GMT”;
“Keep-Alive” = “timeout=5, max=100”;
Server = “Apache/2.4.7 (Ubuntu)”;
“Transfer-Encoding” = Identity;
Vary = “Accept-Encoding”;
“X-Debug-Token” = 3b15f2;
“X-Powered-By” = “PHP/5.5.9-1ubuntu4.11”;
} }, NSErrorFailingURLKey=http://192.168.1.31/kuaixiu/web/app_dev.php/apishop/upload, com.alamofire.serialization.response.error.data=<7b22636f 6465223a 312c226d 65737361 6765223a 225c7534 6530615c 75346632 305c7536 3231305c 75353239 665c7566 66303122 2c226461 7461223a 22353566 39303966 35633636 35632e6a 7067227d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}
仔细看下报错信息,大致意思就是在接收数据的时候缺少“text/html”这个内容类型。
解决办法就是在AFNetWorking的responseSerializer里面增加”text/html“这个内容类型。
1
2
3
|
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer = [AFJSONResponseSerializer new ]; manager.responseSerializer.acceptableContentTypes = [ NSSet setWithObjects: @"text/html" , nil ]; |
这样就大功告成了~但是一定要注意,responseSerializer使用之前一定要new一次,不然配置的东西无效。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用