相关疑难解决方法(0)

如何使用Retrofit 2处理空响应体?

最近我开始使用__CODE__,我遇到了解析空响应体的问题.我有一个服务器只响应http代码而没有响应体内的任何内容.如何只处理有关服务器响应的元信息(标题,状态代码等)?

提前致谢!

android square retrofit retrofit2

114
推荐指数
4
解决办法
5万
查看次数

使用Retrofit 2.0和RxJava获取响应状态代码

我正在尝试升级到Retrofit 2.0并在我的android项目中添加RxJava.我正在进行api调用,并希望在服务器发出错误响应的情况下检索错误代码.

Observable<MyResponseObject> apiCall(@Body body);
Run Code Online (Sandbox Code Playgroud)

并在RxJava调用中:

myRetrofitObject.apiCall(body).subscribe(new Subscriber<MyResponseObject>() {
        @Override
        public void onCompleted() {

        }

        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onNext(MyResponseObject myResponseObject) {
           //On response from server
        }
    });
Run Code Online (Sandbox Code Playgroud)

在Retrofit 1.9中,RetrofitError仍然存在,我们可以通过以下方式获得状态:

error.getResponse().getStatus()
Run Code Online (Sandbox Code Playgroud)

如何使用RxJava进行Retrofit 2.0?

android android-networking rx-java retrofit rx-android

101
推荐指数
3
解决办法
5万
查看次数

Retrofit 2.0 beta 4响应获得IllegalArgumentException

我正在使用改造1.9,我创建了注销方法

@GET("/user/logout")
void logoutUser(Callback<Response> callback);

logoutUser(new RequestCallback<Response>(this) {
    @Override
    public void success(Response response, Response response2) {
        settingsService.setUserLoggedOut();
        getMainActivity().finish();
    }
});
Run Code Online (Sandbox Code Playgroud)

我升级到改装2.0 beta 4并使用此代码

@GET("user/logout")
Call<Response> logoutUser();

logoutUser().enqueue(new RequestCallback<Response>(this) {
    @Override
    public void onResponse(Call<Response> call, Response<Response> response) {
        settingsService.setUserLoggedOut();
        getMainActivity().finish();
    }
});
Run Code Online (Sandbox Code Playgroud)

我有这个例外:java.lang.IllegalArgumentException:'retrofit2.Response'不是有效的响应主体类型.你的意思是ResponseBody?

问题是什么?

android retrofit2

2
推荐指数
1
解决办法
1559
查看次数

同步改造2中如何获取http响应状态

我使用 Retrofit 2.0.1 从服务器获取响应,有没有办法在不使用异步方法的情况下获取 HTTP 响应状态?

Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://192.168.8.4/********/***/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        RequestInterface request = retrofit.create(RequestInterface.class);
        HotelDetail hd;

        Call<HotelDetail> call1 = request.getIndividualHotel("1");

       hd = call1.execute().body();
Run Code Online (Sandbox Code Playgroud)

java json retrofit2

2
推荐指数
1
解决办法
2317
查看次数