When I post data in body (x-www-form-urlencoded) it works fine in Postman. But using Retrofit 2.0 Android it does not work.
@Headers("Content-Type: application/x-www-form-urlencoded")
@POST("/api/jsonws/pushUserData")
Call<ResponseBody> pushData(@Body JSONObject jsonObj);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("role","owner");
jsonObject.put("id","27001");
} catch (JSONException e) {
e.printStackTrace();
}
ApiInterface apiInterface1= ApiClient.getClientAuthentication().create(ApiInterface.class);
Call<ResponseBody> responseBodyCall = apiInterface1.pushData(jsonObject);
This code not work.I also try @FormUrlEncoded.
Try using @FormUrlEncoded
and use @Field
instead of @Body
@FormUrlEncoded
@POST("/api/jsonws/pushUserData")
Call<ResponseBody> pushData(@Field("role") String role, @Field("id") String id);
ApiInterface apiInterface1= ApiClient.getClientAuthentication().create(ApiInterface.class);
Call<ResponseBody> responseBodyCall = apiInterface1.pushData("owner","27001");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With