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.
Asked
Active
Viewed 548 times
0
-
unrated to your question, but people have a lot of faith in postman, but it is also just a tool that could make mistakes – a_local_nobody Feb 21 '20 at 06:15
-
@a_local_nobody this is weird, why is it happening? – Pooja Singh Feb 21 '20 at 06:19
-
@a_local_nobody can you please post full answer with http login interceptor with add headers also? – Pooja Singh Feb 21 '20 at 06:26
-
i don't do java anymore, i'm sure someone will give you an answer soon, sorry – a_local_nobody Feb 21 '20 at 06:28
-
@a_local_nobody O'o my bad luck then :P – Pooja Singh Feb 21 '20 at 06:28
-
@a_local_nobody 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
-
Any solution you found? – Pooja Singh Feb 21 '20 at 08:24
1 Answers
1
you can use HttpLoggingInterceptor to compare requests and find out what is wrong.
Yrii Borodkin
- 772
- 5
- 7
-
-
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
-
-
-
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 – 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