在我的应用程序中,我使用 Retrofit 库发出同步请求。 PUT
问题是:有时图书馆会抛出EOFException
s。
下面是其中一种情况的堆栈跟踪
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
- bug retrofit.RetrofitError: java.io.EOFException for Android
- 1.4.0 字符串中的新行导致retrofit.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");
因为由于性能原因我需要保持连接活跃。