1.This is the time I use retrofit mistakes
first step:
public interface RequestService {
@POST ("home/indexThree")
Call<RequestBody> getHomeinfo(@Body RequestBody info);
}
second step:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.build();
RequestService requestService = retrofit.create(RequestService.class);
RequestBody body = RequestBody.create(JSON, jsonObject.toString());
Call<RequestBody> homeinfo = requestService.getHomeinfo(body);
homeinfo.enqueue(new Callback<RequestBody>() {
@Override
public void onResponse(Call<RequestBody> call, Response<RequestBody> response) {
System.out.println("response"+response.body().toString());
}
@Override
public void onFailure(Call<RequestBody> call, Throwable t) {
System.out.println("onFailure"+t.getMessage().toString());
}
});
I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this. thx!
using ResponseBody
instead of requestbody
, resolved my case:
public interface RequestService {
@POST ("home/indexThree")
Call<ResponseBody> getHomeinfo(@Body RequestBody info);
}
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