Okhttpclient выбрасывает нелегальное статей, когда сервер отвечает 100-конфликтомAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Okhttpclient выбрасывает нелегальное статей, когда сервер отвечает 100-конфликтом

Сообщение Anonymous »

okhttpclient версии 4-12.0 Отправляет запрос многообработки с использованием конфигурации по умолчанию; Север отвечает 100-конфликтом. После получения пары из 100-концентрации okhttpclient выходит из строя с помощью нелегальной статей состояния 3 .
Другое httpclient (например, curl 7.81.0, Apache httpclient 4.5.13, Vertx и т. Д.) Использование конфигурации по умолчанию, как ожидалось, с тем же сервером. Является ли 100-конфликт не поддерживается Okhttpclient или есть что-то еще, чтобы заставить работу OkhttpClient с ответом 100-континового?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 when Expect 100-continue is not used. This appears to be a bug, as the client is not able to handle 100-continues from the server when it is not expected. Is this the case?

Подробнее здесь: https://stackoverflow.com/questions/795 ... 0-continue
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»