HttpClient4.3 about SSL Certificate requests in https

Source: Internet
Author: User
Tags ssl certificate

HttpClient4.3 about SSL Certificate requests in https

HttpClient4.3 concerning the SSL certificate request in https, go directly to the code here and use the CloseableHttpClient implementation class.

Call this method to create CloseableHttpClient to trust all https SSL certificates

Allow all host names in SSLConnectionSocketFactory to ignore host name verification.

Private static CloseableHttpClient buildSSLCloseableHttpClient () throws Exception {
SSLContext sslContext = new SSLContextBuilder (). loadTrustMaterial (null, new TrustStrategy (){
// Trust all
Public boolean isTrusted (X509Certificate [] chain, String authType) throws CertificateException {
Return true;
}
}). Build ();
// ALLOW_ALL_HOSTNAME_VERIFIER: This host name validator basically disables host name verification and implements an empty operation without throwing a javax.net. ssl. SSLException exception.
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory (sslContext, new String [] {"TLSv1"}, null,
SSLConnectionSocketFactory. ALLOW_ALL_HOSTNAME_VERIFIER );
Return HttpClients. custom (). setSSLSocketFactory (sslsf). build ();
}

Upgrade HttpClient4 from HttpClient3 to HttpClient4

HttpClient tutorial

Use HttpClient to upload and download files

HttpClient for Android requests Https

Android uses HttpClient to download images

HttpClient usage

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.