Retrofit2错误java.io.EOFException:第1行第1列的输入结束 [英] Retrofit2 error java.io.EOFException: End of input at line 1 column 1

查看:322
本文介绍了Retrofit2错误java.io.EOFException:第1行第1列的输入结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Retrofit2调用了 PATCH Web服务,但未调用 onResponse ,而将 onFailure 称为服务的操作在服务器端成功完成完美

I called PATCH web service using Retrofit2 but onResponse is not called and the onFailure is called Despite of the operation of the service is succeeded on the server side perfectly

每当我尝试使用fiddler来检查服务的工作情况时,我发现问题是序列化了服务的即将到来的响应,当使用fiddler时,我发现JSON响应中没有内容,因此Retrofit服务假定它失败,因为没有内容,并且无法序列化EMPTY内容 并给我这个错误

And whenever,I tried to use fiddler to check the service its working , i found the problem is that serializing the coming response of the service and when using fiddler i found that no content of the JSON response so the Retrofit service assumed that its failed because there is no content and it cannot serialize the EMPTY content and give me this error

java.io.EOFException: End of input at line 1 column 1

提琴手原始回复

HTTP/1.1 200 OK
Server: nginx/1.9.4
Date: Wed, 02 Mar 2016 09:55:55 GMT
Content-Type: application/json
Content-Length: 0
Connection: close
Status: 200 OK
X-Content-Type-Options: nosniff

Fiddler Json响应为空

Java中的Web服务

Call<Object> call = TimeCapp.services.accept_invited_alerts(HomeActivity.api_token, alert_id);

call.enqueue(new Callback<Object>()
{
    @Override
    public void onResponse (Call<Object> call, Response<Object> response)
    {
        if (response.isSuccess()) {
            String x = response.body();
        }
    }
    @Override
    public void onFailure (Call<Object>call, Throwable t)
    {
        String x = t.getMessage();//java.io.EOFException: End of input at line 1 column 1
    }
}

我尝试将 object 替换为String,JsonObject,emptyCalssBody ...,但失败

I tried to replace object with String,JsonObject,emptyCalssBody .... but its failed

网络服务的界面

@PATCH("alerts/{alert_id}/accept")
Call<Object> accept_invited_alerts(@Header("X-Api-Token") String  
api_token, @Path("alert_id") int alert_id);

推荐答案

如果正文为空,则仅返回void

just return void instead, if the body is empty

@PATCH("alerts/{alert_id}/accept") Call<Void> accept_invited_alerts(@Header("X-Api-Token") String api_token, @Path("alert_id") int alert_id);

要通过Rx Java进行改造,您可以使用类似的

for retrofit with Rx java you can use something like this

@PATCH("alerts/{alert_id}/accept") Observable<Response<Void>> accept_invited_alerts(@Header("X-Api-Token") String api_token, @Path("alert_id") int alert_id);

这篇关于Retrofit2错误java.io.EOFException:第1行第1列的输入结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆