AFNetWork网络请求-1016问题

Posted 火海希

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AFNetWork网络请求-1016问题相关的知识,希望对你有一定的参考价值。

问题描述:

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://beta-its-api.izhikang.com//login, com.alamofire.serialization.response.error.data={length = 863, bytes = 0x7b227265 74223a74 7275652c 226d7367 ... 636f6465 223a307d }, com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x600001154300> { URL: https://beta-its-api.izhikang.com//login } { Status Code: 200, Headers { curTimestamp = ( "1627285025707", ), Via = ( "txyk8s_51_12,172.31.51.46:30111", ), X-RateLimit-Burst-Capacity = ( "2000", ), gw_end_time = ( "1627285025998", ), gw_start_time = ( "1627285025696", ), s_end_time = ( "1627285025998", ), Server = ( "bj3-txy-zk-gateway-beta-1-7", ), Xes-App = ( "nginx", ), Date = ( "Mon, 26 Jul 2021 07:37:05 GMT", ), X-RateLimit-Replenish-Rate = ( "1000", ), Content-Length = ( "863", ), X-RateLimit-Remaining = ( "1999", ), Connection = ( "keep-alive", ), s_start_time = ( "1627285025698", ), } }}

分析解决:

从log可知,content-type无法解析所以我们需要在AF中添加text/plain类型

AFJSONResponseSerializer类中,228行

self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil];

改:

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

ZKRequestManager类中38行确定有:

sessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];

sessionManager.requestSerializer = [AFJSONRequestSerializer serializer];

以上是关于AFNetWork网络请求-1016问题的主要内容,如果未能解决你的问题,请参考以下文章

AFNetWork网络请求-1016问题

AFNetWork网络请求-1016问题

我是不是需要将 Alamofire 请求打包成 AFNetwork 之类的东西?

AFNetwork 作用和用法详解

如何使用 AFNetwork 的 AFHTTPRequestOperationManager 设置 HTTP 请求正文?

VSCode自定义代码片段14——Vue的axios网络请求封装