0

I'm trying to hit one login API, which also need some headers and body. with the latest version of retrofit, I tried to send headers in both way either with annotation or programatically way, but everytime it says error code 417, exception failed and error body is null, but in postman I'm getting proper reponse.

Pooja Singh
  • 149
  • 2
  • 10

1 Answers1

1

you can use HttpLoggingInterceptor to compare requests and find out what is wrong.

Yrii Borodkin
  • 772
  • 5
  • 7
  • How can you give me some more detail?\? – Pooja Singh Feb 21 '20 at 06:07
  • add `implementation("com.squareup.okhttp3:logging-interceptor:4.4.0")` in `build.gradle`, then for you `OkHttpClient.Builder` invoke `.addNetworkInterceptor(HttpLoggingInterceptor().apply { setLevel(HttpLoggingInterceptor.Level.BODY) })` if you done everything right- full http logs will print in logcat – Yrii Borodkin Feb 21 '20 at 06:16
  • please add this to your answer, at the moment your answer doesn't add much value :) – a_local_nobody Feb 21 '20 at 06:21
  • Can you please full answer? – Pooja Singh Feb 21 '20 at 06:22
  • Make sure I have to add header – Pooja Singh Feb 21 '20 at 06:23
  • I'll add but as of now, I don't know how to add httpinterceptor with add haders – Pooja Singh Feb 21 '20 at 06:24
  • you do not need to add any additional headers. Using HttpLoggingIntercpter you can just manualy compare what okhttp sending to server vs what it must send – Yrii Borodkin Feb 21 '20 at 06:31
  • it is printing this after adding looging interceptor t D/OkHttp: {"nameValuePairs":{"body":{"nameValuePairs":{"customerId":39,"emailId":"aster@lifetrenz.ae","prodId":4,"userPwd":"827ccb0eea8a706c4c34a16891f84e7b"}}}} – Pooja Singh Feb 21 '20 at 07:17
  • so, problems is here - request body is wrong. you cant create DTO `class RequestBody (val body: Body) class Body(val customerId: Int, val emailId: String, val prodId: Int, val userPwd: String)` then change your `interface ApiInterface { @POST("login/desktop/user") Call getTopRatedMovies(@Body RequestBody body); }` – Yrii Borodkin Feb 21 '20 at 07:27
  • I tried. I created User class and added seriliazed name and expose annotations and tried. still same error! – Pooja Singh Feb 21 '20 at 08:24
  • Hi, can you please solve? https://stackoverflow.com/questions/60429082/how-can-i-observe-api-call-based-on-user-submit-button-and-at-same-time-getvalue – Pooja Singh Feb 27 '20 at 10:31