首页 > 其他分享 >RestTemplate去掉https验证

RestTemplate去掉https验证

时间:2023-01-18 16:55:26浏览次数:31  
标签:acceptingTrustStrategy HttpComponentsClientHttpRequestFactory restTemplate RestT

/*@Bean
public RestTemplate restTemplate()
throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;

SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
.build();

SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);

CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(csf)
.build();

HttpComponentsClientHttpRequestFactory requestFactory =
new HttpComponentsClientHttpRequestFactory();

requestFactory.setHttpClient(httpClient);
RestTemplate restTemplate = new RestTemplate(requestFactory);
return restTemplate;
}*/

标签:acceptingTrustStrategy,HttpComponentsClientHttpRequestFactory,restTemplate,RestT
From: https://www.cnblogs.com/ivyJ/p/17060203.html

相关文章