/**
* SSL请求HTTPS 不需要证书,用获取到的Client发起请求即可
* org.apache.http.impl.client.CloseableHttpClient
*/
public static CloseableHttpClient createSSLClientDefault(){
try {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
//信任所有
@Override
public boolean isTrusted(java.security.cert.X509Certificate[] chain, String authType)
throws java.security.cert.CertificateException {
return true;
}
}).build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
} catch (KeyManagementException e) {
LOGGER.error("createSSLClientDefault KeyManagementException error",e);
} catch (NoSuchAlgorithmException e) {
LOGGER.error("createSSLClientDefault NoSuchAlgorithmException error",e);
} catch (KeyStoreException e) {
LOGGER.error("createSSLClientDefault KeyStoreException error",e);
}
return HttpClients.createDefault();
}