首页 > Web开发 > 详细

Https Resttemplate

时间:2019-05-13 19:29:54      阅读:346      评论:0      收藏:0      [点我收藏+]
@Configuration
public class HttpsRestTemplate {

	@Bean
	public RestTemplate restTemplate() {
		SSLContext sslContext = null;
		try {
			sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
				public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
					return true;
				}
			}).build();
		} catch (Exception e) {
			e.printStackTrace();
		}
	    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1" }, null,  
	            new NoopHostnameVerifier());
	    CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
	    HttpComponentsClientHttpRequestFactory httpfactory = new HttpComponentsClientHttpRequestFactory(httpclient);
	    RestTemplate restTemplate = new RestTemplate(httpfactory);
	    return restTemplate;
	}
}

  

Https Resttemplate

原文:https://www.cnblogs.com/pxzxj/p/10858457.html

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