/** * * 方法名:createSSLClientDefault * 作者:zhouyh * 创建时间:2015-10-14 下午03:03:30 * 描述:针对https采用SSL的方式创建httpclient * @return */ 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(); }
使用httpclient必须知道的参数设置及代码写法、存在的风险
参考:
http://jinnianshilongnian.iteye.com/blog/2089792
猜你喜欢
转载自rd-030.iteye.com/blog/2357691
今日推荐
周排行