Android Retrofit: content type as application/x-www-form-urlencoded Android Retrofit: content type as application/x-www-form-urlencoded android android

Android Retrofit: content type as application/x-www-form-urlencoded


In the class where you define your service, modify the related method to follow the pattern below:

@FormUrlEncoded@POST/GET/PUT/DELETE("/your_endpoint")Object yourMethodName(@Field("your_field") String yourField,...);


In retrofit 2 is a little bit different:

@FormUrlEncoded@POST/GET/PUT/DELETE("/your_endpoint")Call<Task> createTask (@Field("your_field") String title); 


You have to add the request header like this :

@Headers("Content-Type: application/x-www-form-urlencoded")

in the interface which has the method declarations.