Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to invoke public okhttp3.RequestBody() with no args

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!

like image 861
ljame Avatar asked Jan 20 '17 06:01

ljame


1 Answers

using ResponseBody instead of requestbody, resolved my case:

public interface RequestService {
@POST ("home/indexThree")
Call<ResponseBody> getHomeinfo(@Body RequestBody info);

}

like image 195
Nabat Farsi Avatar answered Sep 20 '22 12:09

Nabat Farsi