private static RestTemplate restTemplate() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
TrustStrategy acceptingTrustStrategy = new TrustSelfSignedStrategy();
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy)
.build();
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);
return restTemplate;
}
restTemplate https访问报证书错误_Java访问HTTPS时证书验证问题
最新推荐文章于 2025-02-14 16:11:19 发布
本文介绍了如何使用Apache HttpClient构建一个安全的REST模板,通过自定义SSLContext和TrustStrategy,实现对自签名证书的信任。重点在于SSL连接工厂的设置和安全请求的创建。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Llama Factory
模型微调
LLama-Factory
LLaMA Factory 是一个简单易用且高效的大型语言模型(Large Language Model)训练与微调平台。通过 LLaMA Factory,可以在无需编写任何代码的前提下,在本地完成上百种预训练模型的微调
7315

被折叠的 条评论
为什么被折叠?



