EOF在执行同步 PUT 请求时在改造中出现异常
2022-09-01 16:16:17
在我的应用程序中,我使用改造库发出同步请求。问题是:有时库会抛出 s。PUT
EOFException
下面是其中一种情况的堆栈跟踪
29099-29269/com.mycompany.myapp D/Retrofit﹕ java.io.EOFException
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:192)
at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:189)
at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:101)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:676)
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:426)
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:371)
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:466)
at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:73)
at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:321)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
at $Proxy7.addEvents(Native Method)
at com.mycompany.myapp.api.MyService.addEvents(MyService.java:59)
我尝试了以下解决方案,但对我的情况都没有帮助:
- 改造使EOFException只是第一次
- 错误改造。RetrofitError: java.io.EOFException for Android
- 1.4.0 字符串中的新行导致改造。RetrofitError: java.io.EOFException
以下是我在应用中创建的方式:RestAdapter
OkHttpClient okHttpClient = new OkHttpClient();
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(Url)
.setRequestInterceptor(new RequestInterceptor()
{
@Override
public void intercept(RequestFacade request)
{
request.addHeader("Accept", "application/json");
request.addHeader("Content-Type", "application/json");
}
})
.setClient(new OkClient(okHttpClient))
.setLogLevel(RestAdapter.LogLevel.FULL)
.setErrorHandler(new MyErrorHandler())
.build();
有没有人知道这个问题的其他解决方案?
顺便说一句,我不能使用涉及的解决方案,因为出于性能原因,我需要保持我的连接处于活动状态。System.setProperty("http.keepAlive", "false");