Skip to content Skip to sidebar Skip to footer

Sending Various Parameters (json) Using Retrofit 2

This is the interface method: @FormUrlEncoded @POST (“url/myurl') Call sendParameters (@Header('x-imei') String imei, @Header('x-id-cliente') String idCliente, @

Solution 1:

First you can create a custom class which you want to pass as a POST body

classCustomClass {
   String param1;
   String parma2;
   String param3;
   //all of your params with getters and setters
}

Then you change the Retrofit method according to your new CustomClass instance with the @Body annotation:

@POST (“url/myurl")
Call<JsonArray> sendParameters (@Header("x-imei") String imei, @Header("x-id-cliente") String idCliente, @Body CustomClass customClassInstance);

And eventually you make the call to post data:

CustomClasscustomClassInstance=newCustomClass();
customClassInstance.setParam1(...);
//...and so on

Call<JsonArray> peticion= RetrofitClient.getRetrofitClient(getActivity()).sendParameters(settings.getString("imei", ""), settings.getString("idCliente", ""), customClassInstance);

EDIT: removed the @FormUrlEncoded annotation

Post a Comment for "Sending Various Parameters (json) Using Retrofit 2"