RestTemplate调用Https接口
2021-02-17 13:17
标签:cti 示例 str name tpc key strategy play turn 本文简单示例 Java 实例化一个可调用 https 请求的 RestTemplate: RestTemplate调用Https接口 标签:cti 示例 str name tpc key strategy play turn 原文地址:https://www.cnblogs.com/miaoying/p/12956961.htmlpublic static RestTemplate getRestTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
return true;
}
}).build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext,
new String[]{"TLSv1"},
null,
NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(csf)
.build();
HttpComponentsClientHttpRequestFactory requestFactory =
new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
RestTemplate restTemplate = new RestTemplate(requestFactory);
return restTemplate;
}
文章标题:RestTemplate调用Https接口
文章链接:http://soscw.com/index.php/essay/56579.html