升级到httpclint 4.x之后 很多调用方式都发生了改变 关于忽略SSL验证当然也是之前试了很多种方式都不行
后来发现了个方法可以,再次跟大家分享,直接上代码:
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null,
new TrustStrategy() {
public boolean isTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
return true;
}
}).build();
SSLConnectionSocketFactory sslfactory = new SSLConnectionSocketFactory(
sslContext, new String[] { "TLSv1", "TLSv1.2"}, null,
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
CloseableHttpClient httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).setSSLSocketFactory(sslfactory).build();
注意下TLSv1.2 目前主流的都是使用的这种协议方式