简体   繁体   English

改造 2 不可接受的响应

[英]Retrofit2 Not acceptable response

I'm actually trying to get a response from my endpoint, but I'm facing a weird issue, I'm getting a 406 HTTP code in Retrofit response.我实际上是在尝试从我的端点获得响应,但我遇到了一个奇怪的问题,我在 Retrofit 响应中收到了 406 HTTP 代码。

This is the body of my request I'm sending:这是我发送的请求的正文:

   {
    "login":"34413",
    "otp":"51131"
    }

when I send to correct OTP, I get the response from my endpoint当我发送到正确的 OTP 时,我会从我的端点获得响应

{
   "statusResponse":    {
      "statusCode": 200,
      "success": succes
   },
   "person": [object person],
   "token": "...."
}

but in case I'm sending the wrong OTP number, I get a retrofit response code 406 which means I didn't receive anything from my endpoint.但如果我发送了错误的 OTP 号码,我会收到 retrofit 响应代码 406,这意味着我没有从我的端点收到任何东西。

NB: when i try my request from SOAP UI both case works fine and this is the response of wrong otp case:注意:当我尝试来自 SOAP UI 的请求时,两种情况都可以正常工作,这是错误 otp 情况的响应:

    {
   "statusResponse":    {
      "statusCode": 406,
      "success": false
   },
   "person": null,
   "token": null
}

Do you have any idea what causing the issue?你知道是什么导致了这个问题吗?

I think retrofit is returning the same response as your soap client as long as the request is the same.我认为 retrofit 只要请求相同,就会返回与您的 soap 客户端相同的响应。 If no interceptors are involved.如果不涉及拦截器。

The common issue is that you are probably expecting the response body to have your json, however with Retrofit in case of unsuccessful response you have to check the errorbody instead of the body then call string() to get its content.常见的问题是您可能希望响应正文具有您的 json,但是对于 Retrofit,如果响应不成功,您必须检查错误正文而不是正文,然后调用string()以获取其内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM