在Spring RestTemplate中禁用SSL证书验证 [英] Disabling SSL Certificate Validation in Spring RestTemplate
问题描述
我在两台不同的计算机上有两个基于Spring的Web应用程序A和B.
I am having two Spring based web apps A and B, on two different machines.
我想从Web应用程序A到Web应用程序B进行https调用,但是我在计算机B中使用了自签名证书.因此,我的HTTPS请求失败.
I want to make a https call from web app A to web app B, however I am using a self-signed certificate in Machine B. So my HTTPS request fails.
在Spring中使用RestTemplate时如何禁用https证书验证?我想禁用验证,因为Web应用程序A和B都在内部网络中,但是数据传输必须通过HTTPS进行
How can I disable https certificate validation when using RestTemplate in Spring ? I want to disable validation because both web app A and B are within the internal network, but data transfer has to happen over HTTPS
推荐答案
您需要添加的是自定义HostnameVerifier
类,绕过证书验证并返回true
What you need to add is a custom HostnameVerifier
class bypasses certificate verification and returns true
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
这需要适当地放置在您的代码中.
This needs to be placed appropriately in your code.
这篇关于在Spring RestTemplate中禁用SSL证书验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!