码迷,mamicode.com
首页 > Web开发 > 详细

httpclient4.4信任所有请求支持https

时间:2017-04-28 20:17:16      阅读:613      评论:0      收藏:0      [点我收藏+]

标签:default   bool   uil   algo   client   ted   pcl   tom   close   

//https信任所有请求创建
public static 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();
    }

 

httpclient4.4信任所有请求支持https

标签:default   bool   uil   algo   client   ted   pcl   tom   close   

原文地址:http://www.cnblogs.com/jokerpu/p/6782767.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!