title: How to resolve javax.net.ssl.SSLHandshakeException
body: <p>How do i make an HTTPS get request using HttpClient? I have done a lot of searching and nothing seems to work for me - a lot of the solutions online are also depending on deprecated api calls :( </p>
  
  <p>Currently, I have followed the code at the following link (Section: Get Server Certificates): <a href="http://memorynotfound.com/apache-httpclient-get-server-certificates/" rel="nofollow noreferrer">http://memorynotfound.com/apache-httpclient-get-server-certificates/</a></p>
  
  <p>My code is as follows:</p>
  
  <pre><code>HttpResponseInterceptor certificateInterceptor = new HttpResponseInterceptor() {
      @Override
      public void process(HttpResponse httpResponse, HttpContext context) throws HttpException, IOException {
          ManagedHttpClientConnection routedConnection = (ManagedHttpClientConnection)context.getAttribute(HttpCoreContext.HTTP_CONNECTION);
          SSLSession sslSession = routedConnection.getSSLSession();
          if (sslSession != null) {
  
              // get the server certificates from the {@Link SSLSession}
              Certificate[] certificates = sslSession.getPeerCertificates();
  
              // add the certificates to the context, where we can later grab it from
              this.context.setAttribute(PEER_CERTIFICATES, certificates);
          }
      }
  };
  
     this.httpClient = HttpClients
              .custom()
              .addInterceptorLast(certificateInterceptor)
              .build();
  </code></pre>
  
  <p>This however results in the following error:</p>
  
  <pre><code>javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  </code></pre>
  
  <p>Why am I getting this exception and how do I fix it? Any help would be greatly appreciated!</p>