Retrofit Sending Json
Solution 1:
You don't need to mention that:
@Headers({
"Accept: application/json",
"Content-Type: application/json"
})
So remove this from your code.
test is boolean in your postman request but here you are passing as string so change following:
JsonObjectobjMerchant=newJsonObject();
objMerchant.addProperty("apiLogin", "XXXXXXXXXXX");
objMerchant.addProperty("apiKey","XXXXXXXXXXXXXX");
JsonObjectobjPing=newJsonObject();
objPing.addProperty("test", "false");
objPing.addProperty("language","es");
objPing.addProperty("command","PING");
objPing.add("merchant",objMerchant);
to:
JsonObjectobjMerchant=newJsonObject();
objMerchant.addProperty("apiLogin", "XXXXXXXXXXX");
objMerchant.addProperty("apiKey","XXXXXXXXXXXXXX");
JsonObjectobjPing=newJsonObject();
objPing.addProperty("test", false);
objPing.addProperty("language","es");
objPing.addProperty("command","PING");
objPing.add("merchant",objMerchant);
Test attribute is boolean in your postman request but here you were passing as string.
Solution 2:
Why there's no endpoint in @POST("./")?
Basically BASE_URL should be https://api.payulatam.com/ and your POST endpoint should be
@POST("payments-api/4.0/service.cgi/")
Besides, why are you creating request body manually? You can use a POJO class to serialize the request and I think it will be easier to handle that way. For example,
public class Request{
@SerializedName("language")
public String language; //you can use private as well
}
and to create the request,
Request request = new Request();
request.language = "es";
So in your interface, put it this way:
Call<Ping> sendPing(@Body Request request);
Can you try this and see?
Updated request object from postman request:
publicclassRequest{@SerializedName("test")public boolean test;
@SerializedName("language")public String language;
@SerializedName("command")public String command;
@SerializedName("merchant")public Merchant merchant;
publicclassMerchant{
@SerializedName("apiLogin")public String apiLogin;
@SerializedName("apiKey")public String apiKey;
}
}
Post a Comment for "Retrofit Sending Json"