You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Oleg Kalnichevski (JIRA)" <ji...@apache.org> on 2019/04/25 07:20:00 UTC

[jira] [Resolved] (HTTPCLIENT-1987) Cannot request when do over https proxy

     [ https://issues.apache.org/jira/browse/HTTPCLIENT-1987?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski resolved HTTPCLIENT-1987.
-------------------------------------------
    Resolution: Not A Bug

[~takemefly] HttpClient 4.5 and HttpClient 5.0 presently do not support connection tunneling via https proxies.

Oleg

> 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
>            Priority: Major
>
> When I request a http over https proxy use as below code .
> {code:java}
> HttpHost proxy = new HttpHost("127.0.0.1", 5000, "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));
>     }
> {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.  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org