// 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 context.setAttribute(PEER_CERTIFICATES, certificates); } };
// create closable http client and assign the certificate interceptor CloseableHttpClienthttpClient= HttpClients.custom().addInterceptorLast(certificateInterceptor).build();
try {
// make HTTP GET request to resource server HttpGethttpget=newHttpGet("https://www.baidu.com"); System.out.println("Executing request " + httpget.getRequestLine());
// create http context where the certificate will be added HttpContextcontext=newBasicHttpContext(); httpClient.execute(httpget, context);
// obtain the server certificates from the context Certificate[] peerCertificates = (Certificate[])context.getAttribute(PEER_CERTIFICATES);