Okhttp. Exception java.io.IOException: unexpected end of stream on Connection
Asked Answered
U

1

6

I faced with an issue, about third of all OkHttpClient newCall(request).execute(); requests to the server fails with this exception:

Exception java.io.IOException: unexpected end of stream on Connection{[REDACTED_DOMAIN_NAME]:80, proxy=DIRECT@ hostAddress=[REDACTED_DOMAIN_NAME]/[REDACTED_IP_ADDRESS] cipherSuite=none protocol=http/1.1}

I disabled the validation of certificates. What could be the reason of this behavior?

Ubiquitous answered 22/3, 2018 at 15:57 Comment(2)
Probably issues with server or network.Jesse
@Okas, thank you, it was really network issue. The reason was that the server address was blacklisted by Russia's state regulator (it blacklisted more than 14.5 million IP addresses and many companies suffered from this)Ubiquitous
L
0

The OkHttpClient's default request protocol is HTTP2.0. Some Web Services are required HTTP1.1 requests.

Add protocols(listOf(Protocol.HTTP_1_1)) line to your OkHttpClient.

Example;

val okHttpClient = OkHttpClient.Builder()
                    .protocols(listOf(Protocol.HTTP_1_1))
                    .readTimeout(40, TimeUnit.SECONDS)
                    .connectTimeout(40, TimeUnit.SECONDS)
                    .addInterceptor(loggingInterceptor)
                    .addInterceptor(authInterceptor)
                    .retryOnConnectionFailure(true)
                    .build()
Launder answered 11/1, 2021 at 13:38 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.