gpt4 book ai didi

android - 改造okhttp获取随机eofexception

转载 作者:太空宇宙 更新时间:2023-11-03 10:39:16 26 4
gpt4 key购买 nike

我在调用 REST WS 的 Android 应用程序上工作。该服务本身工作正常(使用 Postman 测试)但我偶尔会从 Android 收到此异常:

: java.io.IOException: unexpected end of stream on com.squareup.okhttp.Address@2cd22e9d
at com.squareup.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:201)
at com.squareup.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127)
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:737)
at com.squareup.okhttp.internal.http.HttpEngine.access$200(HttpEngine.java:87)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:722)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:576)
at com.squareup.okhttp.Call.getResponse(Call.java:287)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:243)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:205)
at com.squareup.okhttp.Call.execute(Call.java:80)
at retrofit.client.OkClient.execute(OkClient.java:53)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.io.EOFException: \n not found: size=0 content=...
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:201)
at com.squareup.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:186)
at com.squareup.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127) 
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:737) 
at com.squareup.okhttp.internal.http.HttpEngine.access$200(HttpEngine.java:87) 
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:722) 
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:576) 
at com.squareup.okhttp.Call.getResponse(Call.java:287) 
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:243) 
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:205) 
at com.squareup.okhttp.Call.execute(Call.java:80) 
at retrofit.client.OkClient.execute(OkClient.java:53) 
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326) 
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220) 
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278) 
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
at retrofit.Platform$Android$2$1.run(Platform.java:142) 
at java.lang.Thread.run(Thread.java:818) 

我在网上找到了一些关于错误的信息,但我不确定。另外,奇怪的是有时可以,有时不能,而无需我更改代码中的任何内容。该异常说明了有关缺少结束行字符的内容。我必须把它放在 URL 中吗?这是一些代码。谢谢。

API接口(interface)

public interface ApiInterface {

@Headers({"Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJkb25hdG8iLCJ1c2VySWQiOiIxIiwicm9sZSI6IlJPTEVfQURNSU4ifQ.yNVtQMfMasfR7nfBgtjtmlXMM8Gpfjvf_FDz1sMiaSJxUvLDyC9sjm-XSEkJdfGy4JasfweRrRUGc3gHpMRA",
"Accept: application/json",
"Content-Type: application/json;charset=utf-8"})
@POST("/todo/getTodoList")
public void getTodoList(@Body BaseRequest request, Callback<GetTodoListResponse> response);
}

Controller

 RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("http://www.myUrl.com/app/rest").setLogLevel(RestAdapter.LogLevel.FULL).setConverter(new GsonConverter(builder.create()))
.setClient(new OkClient(new OkHttpClient()))
.build();
ApiInterface methods = restAdapter.create(ApiInterface.class);
Callback<GetTodoListResponse> callback = new Callback<GetTodoListResponse>() {
@Override
public void success(GetTodoListResponse o, Response response) {
todoList = o.getTodoList();
Log.d("CardController", "TodoList: " + todoList);
if (!o.isOutcome()) {
Log.e("CardController", "Error fetching todoList");
todoList = new ArrayList<Todo>();
} else {
setChanged();
myMethod();
}
}

@Override
public void failure(RetrofitError retrofitError) {
Log.e("Retrofit", "Error fetching todoList: ", retrofitError);
}
};
methods.getTodoList(new AuraBaseRequest(), callback);

最佳答案

在我的例子中,服务器端是 Spring MVC,我收到了这个错误。发生此错误的原因是某些安全检查(500 返回状态),但改造中的错误是流的意外结束。一旦安全检查被绕过,我就能够得到响应。

希望它能对将来的人有所帮助。

关于android - 改造okhttp获取随机eofexception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37324263/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com