SocketTimeoutException using POST-Redirect-GET pattern with Retrofit and OkHttp

StackOverflow https://stackoverflow.com/questions/22647023

  •  21-06-2023
  •  | 
  •  

Pergunta

I am using Retrofit 1.5.0 and OkHttp to invoke a REST POST endpoint that returns a 302 for a subsequent GET request. Using OkHttp 1.3.0 this works as expected. However, after upgrading to OkHttp 1.5.0 (or later), I receive a SocketTimeoutException even though both requests were made. My RestAdapter uses the default OkClient.

The OkHttp team recently fixed an issue (https://github.com/square/okhttp/issues/296) where the Content-Length header was being preserved from the POST request to the GET request. Looking at the code for OkHttp 1.5.2, the fix seems to be achieved by removing that header in com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponse() before creating the GET Request; however, if the instance field fixedContentLength is not -1, the Content-Length header is recreated in com.squareup.okhttp.internal.http.HttpURLConnectionImpl.newHttpEngine(). The fixedContentLength field is set by retrofit.client.UrlConnectionClient.prepareRequest() before the original POST request, so the upshot is that the Content-Length header is present with a positive value when the GET request is issued.

Is this a bug or am I missing something from a configuration standpoint?

Foi útil?

Solução

Sounds like a bug to me. Report it against OkHttp's bugtracker and I'll have a fix for you very soon.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top