EOF在执行同步 PUT 请求时在改造中出现异常

2022-09-01 16:16:17

在我的应用程序中,我使用改造库发出同步请求。问题是:有时库会抛出 s。PUTEOFException

下面是其中一种情况的堆栈跟踪

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)

我尝试了以下解决方案,但对我的情况都没有帮助:

以下是我在应用中创建的方式: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");


答案 1

此问题通常是由网络错误引起的。如果它一致地再现,请考虑内容长度和请求超时的潜在原因。有时,超时的网络请求可能会返回不正确的文件结尾。这将引发此错误。


答案 2

可能是 EOF 作为丢失的网络连接或超时。尝试增加超时并确保设置了保持活动状态。


推荐