restTemplate 信任所有SSL证书
程序员文章站
2022-03-05 13:36:06
...
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate() throws NoSuchAlgorithmException, KeyManagementException {
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, new TrustManager[]{new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[]{};
}
}}, new java.security.SecureRandom());
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(csf)
.build();
HttpComponentsClientHttpRequestFactory requestFactory =
new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
RestTemplate restTemplate = new RestTemplate(requestFactory);
//处理中文乱码
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
return restTemplate;
}
}
上一篇: jna 从入门到快速开发(一)
下一篇: 详细解读分析JavaScript代码模块
推荐阅读
-
浏览器信任的 IP SSL证书申请仅需1-3天
-
浏览器信任的 IP SSL证书申请仅需1-3天
-
iOS 10.3下Charles抓包ssl证书信任问题的解决办法
-
使用 Let's Encrypt 为 Zimbra-8.8.15 安装可信任的SSL证书
-
使用阿里云免费证书为 Zimbra 安装可信任的SSL证书
-
spring boot 使用RestTemplate信任所有https请求
-
Android OkHttp信任所有证书
-
Java 信任所有SSL证书(解决PKIX path building failed问题)
-
Java 信任所有SSL证书(解决PKIX path building failed问题)
-
【笔记】Java 信任所有SSL证书(解决PKIX path building failed问题)