android - 无法调用没有参数的 public okhttp3.RequestBody()

标签 android okhttp

1.这是我使用retrofit错误的时候

第一步:

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

第二步:

 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());
        }
    });

我在网上找了很久。但是没有用。请帮助或尝试提供一些想法如何实现这一目标。谢谢!

最佳答案

使用 ResponseBody 而不是 requestbody,解决了我的问题:

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

关于android - 无法调用没有参数的 public okhttp3.RequestBody(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41757477/

相关文章:

android - 是否可以在主屏幕上隐藏 APP 图标(Cordova - Angular App)

android - Retrofit 在 OKHttp 2.0 的类路径错误上检测到不受支持的 OkHttp

java - OkHttpClient 无法取消通过标签调用

android - Retrofit 2 + rx - 如何在 android 中检查响应来源(网络、缓存或两者)?

java - 无法让 OkHttp 的 response.body.toString() 返回字符串

android - 在特定网络上重定向 OkHttp3 请求

android - 条码 fragment (Zxing库)

android - React-Native 中的抽屉导航

android - jQuery 手机 : how exit an application on button click in native android application

android - 重复的 zip 条目 [classes.jar :android/support/v4/media/MediaBrowserCompat$MediaItem$1. 类]