httpClient 处理SSL问题
2016-08-19 16:09
351 查看
public CloseableHttpClient createSSLClientDefault() {
try {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
// 信任所有
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyStoreException e) {
e.printStackTrace();
}
return HttpClients.createDefault();
}
try {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
// 信任所有
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyStoreException e) {
e.printStackTrace();
}
return HttpClients.createDefault();
}
相关文章推荐
- android webview & httpclient 处理 ssl (https)验证
- Cookies,SSL,httpclient的多线程处理,HTTP方法
- NO.91 SSLPeerUnverifiedException 问题之解决(附HttpClientUtils升级版)
- 解决: httpclient ssl 验证导致死锁问题
- HttpClient获取服务器JSON数据问题处理
- 关于 httpclient4.3.5 ssl handShake时卡住的问题
- httpWebRequest WebClient下载慢的问题处理
- Cookies,SSL,httpclient的多线程处理,HTTP方法
- Cookies,SSL,httpclient的多线程处理,HTTP方法 .
- HTTPCLIENT SSL(https)通讯 遇到的问题
- docker server gave HTTP response to HTTPS client 问题处理办法
- Cookies,SSL,httpclient的多线程处理,HTTP方法 (zt)
- HttpClient_javax.net.ssl.SSLHandshakeException: sun.security.validator 问题解决,与环境有关
- Cookies,SSL,httpclient的多线程处理,HTTP方法
- Cookies,SSL,httpclient的多线程处理,HTTP方法
- Cookies,SSL,httpclient的多线程处理,HTTP方法
- Httpclient SSLContextBuilder deprecated 问题
- HttpClient POST 的 UTF-8 编码问题
- 使用java处理HTTP返回302的问题
- httpClient中文乱码问题解决(wap提交)