1

I am using Retrofit v2.4.0 in my project. I need to get token using one API call and using this token in header of the POST request I should use another API call where I should add one header and two parameter to the body of the request. The following code is of the second API call (JavaRx is used):

@FormUrlEncoded
@POST("auth/sendCode")
@Headers("Content-Type: application/json")
Single<SendCodeResponse> sendCode(@Header("token") String token,
                                  @Field("phoneNumber") String phoneNumber,
                                  @Field("langCode") String langCode);

However, it is not working. When I log my request, it is showing that the request body is not correct. What is wrong with my code above?

piet.t
  • 11,718
  • 21
  • 43
  • 52
Muhammadjon
  • 1,476
  • 2
  • 14
  • 35
  • remove "content-type" header – Mehta Mar 14 '19 at 09:50
  • @Mehta didn't work. (however, "Content-Type" should be there) – Muhammadjon Mar 14 '19 at 09:55
  • Possible duplicate of [How to dynamically set headers in Retrofit (Android)](https://stackoverflow.com/questions/29884967/how-to-dynamically-set-headers-in-retrofit-android) – Adil Mar 14 '19 at 09:59
  • Agree "Content-Type" should be there but you have already defined @FormUrlEncoded (request params in form data) and then you are defining "application/json"( request body in json format-raw data) – Mehta Mar 14 '19 at 10:00
  • Also check if key name for your security token is "token" or something else. – Mehta Mar 14 '19 at 10:02

0 Answers0