首页 > 编程语言 > 详细

Https 忽略证书\使用自定义证书的java代码实现

时间:2017-02-05 23:57:22      阅读:522      评论:0      收藏:0      [点我收藏+]
public SSLContext createIgnoreVerifySSL() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {

        SSLContext sc = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {

            public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                return true;
            }

        }).build();

        return sc;
    }

    protected HttpClient getHttpClient() throws Exception {

        HttpClientBuilder builder = HttpClientBuilder.create();
        SSLConnectionSocketFactory sslConnSocketFactory = new SSLConnectionSocketFactory(createIgnoreVerifySSL());
        builder.setSSLSocketFactory(sslConnSocketFactory);

        Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory> create().register("https", sslConnSocketFactory).build();

        HttpClientConnectionManager ccm = new BasicHttpClientConnectionManager(registry);

        builder.setConnectionManager(ccm);

        return builder.build();

    }

 

Https 忽略证书\使用自定义证书的java代码实现

原文:http://www.cnblogs.com/wblade/p/6368900.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!