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];

猜你喜欢

转载自blog.csdn.net/u011374880/article/details/119114532