Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

okhttp proxy https is failed #3782

Closed
zi6xuan opened this issue Jan 18, 2018 · 4 comments
Closed

okhttp proxy https is failed #3782

zi6xuan opened this issue Jan 18, 2018 · 4 comments

Comments

@zi6xuan
Copy link

zi6xuan commented Jan 18, 2018

version: okhttp-3.9.1
os: Windows7,AndroidEmulator25,26
compileSDKVersion: 26
i set the proxy for okhttp,and request "https://www.google.com",but get a error now.
don't set proxy it's can work
mProxyAuthenticator = new Authenticator() {
@Override
public Request authenticate(Route route, Response response) throws IOException {
String credential = Credentials.basic(username, password);
return response.request().newBuilder()
.header("Proxy-Authorization", credential)
.build();
}
};
mInetSocketAdress = new InetSocketAddress(proxyHost, proxyPort);

OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
builder.proxy(new Proxy(Proxy.Type.HTTP, mInetSocketAdress))
.proxyAuthenticator(mProxyAuthenticator);
Request request = new Request.Builder()
.url(url)
.build();
OkHttpClient client = builder.build();
response = client.newCall(request).execute();
....
errors
01-18 01:00:12.088 4338-4449/com.nttd.app.CarCooperation W/System.err: java.io.IOException: unexpected end of stream on null
01-18 01:00:12.088 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:205)
01-18 01:00:12.088 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.connection.RealConnection.createTunnel(RealConnection.java:354)
01-18 01:00:12.088 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.connection.RealConnection.connectTunnel(RealConnection.java:211)
01-18 01:00:12.088 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:152)
01-18 01:00:12.088 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:256)
01-18 01:00:12.088 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)
01-18 01:00:12.088 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)
01-18 01:00:12.088 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
01-18 01:00:12.088 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
01-18 01:00:12.088 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.RealCall.execute(RealCall.java:77)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at com.nttd.app.CarCooperation.http.HttpManager$4.run(HttpManager.java:164)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at java.lang.Thread.run(Thread.java:761)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: Caused by: java.io.EOFException: \n not found: limit=0 content=…
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:227)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.http1.Http1Codec.readHeaderLine(Http1Codec.java:212)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
01-18 01:00:12.089 4338-4449/com.nttd.app.CarCooperation W/System.err: ... 21 more

then I try the HttpClient API,same the network,get the message
httpClient=Code=407 Proxy Authentication Required
why the OKhttp not back the code 407

@zi6xuan zi6xuan closed this as completed Jan 19, 2018
@Navi91
Copy link

Navi91 commented Jan 22, 2018

Hello!
How did you resolve this issue?

@zi6xuan
Copy link
Author

zi6xuan commented Jan 23, 2018

Yes, I fixed this bug, but I have to change the source code

private Request createTunnelRequest() {
return new Request.Builder()
.url(route.address().url())
.header("Host", Util.hostHeader(route.address().url(), true))
.header("Proxy-Connection", "Keep-Alive") // For HTTP/1.0 proxies like Squid.
.header("User-Agent", Version.userAgent())
.build();
}

OKHttp3.9.1,I watch the source code and debug it,I found the createTunnelRequestnot add the Proxy-Authorization,so The https request is can not be connected

private Request createTunnelRequest(Call call) {
Request.Builder builder = new Request.Builder()
.url(route.address().url())
.header("Host", Util.hostHeader(route.address().url(), true))
.header("Proxy-Connection", "Keep-Alive") // For HTTP/1.0 proxies like Squid.
.header("User-Agent", Version.userAgent());
String value = call.request().header("Proxy-Authorization");
if (value != null) {
builder.header("Proxy-Authorization", value);
}
return builder.build();
}

@Navi91 I hope for your help

@zi6xuan zi6xuan reopened this Jan 23, 2018
@zi6xuan zi6xuan closed this as completed Jan 23, 2018
@Navi91
Copy link

Navi91 commented Feb 21, 2018

@zi6xuan Thank you for reply!

@yeyb
Copy link

yeyb commented Jul 17, 2018

@zi6xuan This problem can only be solved by modifying the source code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants