我需要使用https / ssl测试在localhost上运行的REST端点(不幸的是,无法将其更改为http)。问题在于,由于它仅用于测试目的,因此只包含Java不喜欢的自签名证书。
为使其正常工作,我尝试允许将localhost作为主机名:
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
new javax.net.ssl.HostnameVerifier(){
public boolean verify(String hostname,
javax.net.ssl.SSLSession sslSession) {
if (hostname.equals("localhost")) {
return true;
}
return false;
}
});
并进一步将自签名证书添加到我的密钥库中。
但是我仍然遇到以下错误:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
除了禁用整个ssl验证过程外,还有谁知道其他事情吗?