1

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 :(

Currently, I have followed the code at the following link (Section: Get Server Certificates): http://memorynotfound.com/apache-httpclient-get-server-certificates/

My code is as follows:

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

This however results in the following error:

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

Why am I getting this exception and how do I fix it? Any help would be greatly appreciated!

BigBug
  • 6,202
  • 23
  • 87
  • 138
  • Did you read this question https://stackoverflow.com/questions/6659360/how-to-solve-javax-net-ssl-sslhandshakeexception-error? – Mayoares Nov 22 '17 at 11:18

0 Answers0