当前位置:   article > 正文

AFNetworking发送Post请求报415错误处理_userinfo={nslocalizeddescription=request failed: u

userinfo={nslocalizeddescription=request failed: unsupported media type (415
问题描述:

使用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"
    );
} }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
解决方案:

通过后台swagger请求可以成功,使用代码不行经抓包后发现
后台传参数如下
1
我们代码请求如下
2
经排查发现afnetworking做了处理
3
同时请求时设置了
[manage.requestSerializer setValue:@“application/json” forHTTPHeaderField:@“Content-Type”];
修改内部代码,传值多加了个判断,就正常拿到值了
4

问题的根源是AFNetworking上传的Post请求包体和后台要求的格式有出入到值415错误的出现,问题排查到双方可沟通具体格式

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/460698
推荐阅读
相关标签
  

闽ICP备14008679号