Okhttpclient Version 4-12.0 sendet eine Multipart-Form-Anforderung mithilfe der Standardkonfiguration; Sever antwortet mit 100 Anpassungen. Nachdem ein paar von 100-kontinuierlich mit illegalStateException Zustand 3 . Wird 100-kontinuiert nicht von Okhttpclient unterstützt oder ist noch etwas erforderlich, um Okhttpclient mit 100-kontinuierlicher Antwort zu bearbeiten?Exception in thread "main" java.lang.IllegalStateException: state: 3
at okhttp3.internal.http1.Http1ExchangeCodec.newFixedLengthSource(Http1ExchangeCodec.kt:227)
at okhttp3.internal.http1.Http1ExchangeCodec.openResponseBodySource(Http1ExchangeCodec.kt:132)
at okhttp3.internal.connection.Exchange.openResponseBody(Exchange.kt:129)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:130)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
< /code>
RequestBody fileBody = RequestBody.create(MediaType.parse("application/octet-stream"), file);
MultipartBody multipartBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("somefile",file.getName(),fileBody)
.build();
Request request = new Request.Builder()
// .header("Expect","100-continue") //makes no difference ...
.url(url)
.post(multipartBody)
.build();
try (Response response = client.newCall(request).execute()){
log.info("Response Code {}",response.code());
} catch (IOException e) {
...
}
< /code>
Issue seems to be similar to https://github.com/square/okhttp/issues/3628 and is present in version 3.11; Any suggestion to get 100-continue working ?
==================================================================
On further investigation
100-continue response from the server
Response{protocol=http/1.1, code=100, message=Continue, url=http://localhost:8443/someendpoint}
< /code>
CallServerInterceptor:
response = if (forWebSocket && code == 101) {
// Connection is upgrading, but we need to ensure interceptors see a non-null response body.
response.newBuilder()
.body(EMPTY_RESPONSE)
.build()
} else {
response.newBuilder()
.body(exchange.openResponseBody(response))
.build()
}
< /code>
I think the issue is caused by setting the state to
STATE_READ_RESPONSE_HEADERS on the first 100-Continue response and expect the state to be in STATE_OPEN_RESPONSE_BODY when subsequent 100-Continue responses are received. If not it will throw illegalStateException.
It appears OkHttpClient is not able to ignore subsequent 100-Continue responses from the server. Is this the case?
Okhttpclient löst illegalStateException aus, wenn der Server mit 100-kontinuierlicher Reaktion reagiert ⇐ Java
-
- Similar Topics
- Replies
- Views
- Last post