[Question] Proxy connection always fail with unexpected end of stream.
See original GitHub issueHi,
On some proxies (squid proxy) OKHttpClient works well. On others (also squid proxies), for an unknown reason, I always get the "unexpected end of stream" error (Caused by: java.io.EOFException: \n not found: size=0 content). For all the browsers and other http clients (java, apache, jetty), the proxy works.
Exception in thread "main" java.io.IOException: unexpected end of stream at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:215) at okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127) at okhttp3.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:732) at okhttp3.internal.http.HttpEngine.access$2(HttpEngine.java:726) at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:714) at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:566) at okhttp3.RealCall.getResponse(RealCall.java:245) at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:200) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:162) at okhttp3.RealCall.execute(RealCall.java:59) at testok.run(testok.java:54) at testok.main(testok.java:61) Caused by: java.io.EOFException: \n not found: size=0 content=... at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:196) at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:191) ... 11 more
I have tried to debug it using the OKHttp and okio sources, by sniffing with Wireshark, but no luck. Somehow the server response is missing. How can I debug this?
The code that I use is quite simple.
` Authenticator proxyAuthenticator = new Authenticator() { public Request authenticate(Route route, Response response) throws IOException { String credential = Credentials.basic(user, password); return response.request().newBuilder() .header(“Proxy-Authorization”, credential) .build(); } };
OkHttpClient client = new OkHttpClient.Builder()
.protocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1, Protocol.SPDY_3))
.connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy, port)))
.proxyAuthenticator(proxyAuthenticator)
.authenticator(proxyAuthenticator)
.build();
Request request = new Request.Builder()
.url(url)
.header("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0")
.build();
Response response = client.newCall(request).execute();
System.out.println("response " + response.code());
return response.body().string();`
Best Regards, Stefan Matei
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
Hi. Is there any solution for described problem in any version? I have the same problem
Duplicate of https://github.com/square/okhttp/pull/2458