0

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.

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

{
   "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.

NB : when i try my request from SOAP UI both case works fine and this is the response of wrong otp case :

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

Do you have any idea what causing the issue?

ismail alaoui
  • 5,748
  • 2
  • 21
  • 38

1 Answers1

1

I think retrofit is returning the same response as your soap client as long as the request is the same. 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.

ismail alaoui
  • 5,748
  • 2
  • 21
  • 38
113408
  • 3,364
  • 6
  • 27
  • 54
  • thanks , you are right , i solved by getting my json as you suggest , this way : jObjError = new JSONObject(response.errorBody().string()); – ismail alaoui Jun 18 '20 at 17:49