Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1987

Cannot request when do over https proxy

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not A Bug
    • 4.5.8
    • None
    • HttpClient (Windows)
    • None

    Description

      When I request a http over https proxy use as below code .

      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));
          }
      

      It will throw like exceptions below:

      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)
      
       
      

      But when I set chrome browser the https proxy,I can do access the websites with https over the https proxy.  

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            takemefly takemefly
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: