Charles抓包map local后出现“failed: unacceptable content-type: text/plain“

在使用Charles进行maplocal映射时,遇到一个因content-type为text/plain的响应导致的alamofire错误(-1016)。尽管代码已设置接受text/plain类型,问题仍然存在。解决方法是调整Charles配置以适应这种内容类型。

Charles 抓包map local 修改 映射到本地数据 出现如下报错

返回ErrorUrl==https://xxxx
返回Error==Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/plain" UserInfo={NSLocalizedDescription=Request failed: unacceptable content-type: text/plain, NSErrorFailingURLKey=https://xxx?timestamp=1688982930645, com.alamofire.serialization.response.error.data={length = 7601, bytes = 0x7b0a0922 72657422 3a207472 75652c0a ... 7d5d0a09 7d5d0a7d }, com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x282fda420> { URL: https://read-beta.xwuad.com/pagerecommend/v2/recommendList?timestamp=1688982930645 } { Status Code: 200, Headers {
  "Content-Length" : [
    "7601"
  ],
  "Content-Type" : [
    "text\/plain"
  ],
  "x-charles-map-local" : [
    "\/Users\/leihuai\/Desktop\/firstpage.txt"
  ]
} }}

意思很明显缺少 text/plain 的数据解析格式,检查代码发现 response中明显已经添加了

netManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain", nil];

解决办法,可以对Charles做如下操作


image.png
image.png
image.png
image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容