0
有沒有辦法使用Apache的HttpClient(v4)獲取網站的證書詳細信息?我可以使用javax.net.ssl.HttpsURLConnection.getServerCertificates()
獲得網站證書,但我使用的是Apache的HttpClient用於我的連接,並且希望使用相同的庫。有沒有辦法使用Apache的HttpClient獲取網站的證書?
我需要像證書的頒發者,到期算法等
有沒有辦法使用Apache的HttpClient(v4)獲取網站的證書詳細信息?我可以使用javax.net.ssl.HttpsURLConnection.getServerCertificates()
獲得網站證書,但我使用的是Apache的HttpClient用於我的連接,並且希望使用相同的庫。有沒有辦法使用Apache的HttpClient獲取網站的證書?
我需要像證書的頒發者,到期算法等
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.addRequestInterceptor(new HttpRequestInterceptor() {
public void process(
HttpRequest request, HttpContext context) throws HttpException, IOException {
HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
ExecutionContext.HTTP_CONNECTION);
SSLSession sslsession = conn.getSSLSession();
if (sslsession != null) {
// Do something useful with the SSL session details
// and if necessary stick the result to the execution context
// for further processing
X509Certificate[] certs = sslsession.getPeerCertificateChain();
for (X509Certificate cert: certs) {
System.out.println(cert);
}
}
}
});
HttpResponse response = httpclient.execute(new HttpGet("https://verisign.com/"));
EntityUtils.consume(response.getEntity());
希望這有助於信息。