takemefly created HTTPCLIENT-1987:
-------------------------------------
Summary: Cannot request when do over https proxy
Key: HTTPCLIENT-1987
URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1987
Project: HttpComponents HttpClient
Issue Type: Bug
Components: HttpClient (Windows)
Affects Versions: 4.5.8
Reporter: takemefly
When I request a http over https proxy use as below code . It will throw like
exceptions below:
{code:java}
Connection released: [id: 0][route:
{tls}->https://127.0.0.1:8118->https://issues.apache.org:443][total kept alive:
0; route allocated: 0 of 2; total allocated: 0 of 20]
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at sun.security.ssl.InputRecord.handleUnknownRecord(InputRecord.java:710)
at sun.security.ssl.InputRecord.read(InputRecord.java:527)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
at
sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at
org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:436)
at
org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:384)
{code}
But when I set chrome browser the https proxy,I can do access the websites with
https over the https proxy.
HttpHost proxy = new HttpHost("127.0.0.1", 8118, "https");
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial( new TrustStrategy() {
@Override
boolean isTrusted(X509Certificate[] chain, String authType) throws
CertificateException {
return true
} }).build();
RequestConfig requestConfig=RequestConfig.custom()
.setConnectTimeout(10000)
.setConnectionRequestTimeout(10000)
.setSocketTimeout(10000).build();
CloseableHttpClient httpclient = HttpClientBuilder
.create()
.setProxy(proxy)
.setSSLHostnameVerifier(new HostnameVerifier() {
@Override
boolean verify(String s, SSLSession sslSession) {
return true
} }).setSSLSocketFactory(new SSLConnectionSocketFactory(sslContext))
.setDefaultRequestConfig(requestConfig)
.build()
HttpHost target = new HttpHost("issues.apache.org", 443, "https");
HttpGet req = new HttpGet("/");
System.out.println("executing request to " + target + " via " + proxy);
HttpResponse rsp = httpclient.execute(target, req);
HttpEntity entity = rsp.getEntity();
System.out.println("----------------------------------------");
System.out.println(rsp.getStatusLine());
Header[] headers = rsp.getAllHeaders();
for (int i = 0; i<headers.length; i++) {
System.out.println(headers[i]);
}
System.out.println("----------------------------------------");
if (entity != null) {
System.out.println(EntityUtils.toString(entity));
}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]