赞
踩
使用AFNetworking请求报错如下:415"Unsupported Media Type",详细信息如下
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unsupported media type (415)" UserInfo={NSLocalizedDescription=Request failed: unsupported media type (415), NSUnderlyingError=0x600002df6100 {Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: application/problem+json" UserInfo={NSLocalizedDescription=Request failed: unacceptable content-type: application/problem+json, NSErrorFailingURLKey=http://demo.bitech.cn/CdHeritagePark/MobileApi/Resource/OrderExt/OrderPay, com.alamofire.serialization.response.error.data={length = 147, bytes = 0x7b227479 7065223a 22687474 70733a2f ... 30346439 352e227d }, com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x6000027c9100> { URL: http://demo.bitech.cn/CdHerit } { Status Code: 415, Headers { "Content-Length" = ( 147 ); "Content-Type" = ( "application/problem+json; charset=utf-8" ); Date = ( "Thu, 24 Sep 2020 09:08:20 GMT" ); "Proxy-Connection" = ( "Keep-alive" ); Server = ( Kestrel ); "X-Powered-By" = ( "ASP.NET" ); } }}}, NSErrorFailingURLKey=http://demo.bitech.cn/CdHeritagePark/MobileApi/Resource/OrderExt/OrderPay, com.alamofire.serialization.response.error.data={length = 147, bytes = 0x7b227479 7065223a 22687474 70733a2f ... 30346439 352e227d }, com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x6000027c9100> { URL: http://demo.bitech.cn/CdHeritagePark/MobileApi/Resource/OrderExt/OrderPay } { Status Code: 415, Headers { "Content-Length" = ( 147 ); "Content-Type" = ( "application/problem+json; charset=utf-8" ); Date = ( "Thu, 24 Sep 2020 09:08:20 GMT" ); "Proxy-Connection" = ( "Keep-alive" ); Server = ( Kestrel ); "X-Powered-By" = ( "ASP.NET" ); } }}
通过后台swagger请求可以成功,使用代码不行经抓包后发现
后台传参数如下
我们代码请求如下
经排查发现afnetworking做了处理
同时请求时设置了
[manage.requestSerializer setValue:@“application/json” forHTTPHeaderField:@“Content-Type”];
修改内部代码,传值多加了个判断,就正常拿到值了
问题的根源是AFNetworking上传的Post请求包体和后台要求的格式有出入到值415错误的出现,问题排查到双方可沟通具体格式
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。