我的代码目前正在尝试ping用户提供的网址。它适用于非HTTPS网站。但是,如果我尝试使用以下内容:https://www.httpsnow.org/,我会收到例外:Could not establish connection. Error is: 'sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target'
以下代码:
try
{
long startTime = DateProvider.getCurrentTimeMillis();
huc = getConnection(url);
huc.setRequestMethod("GET");
huc.setConnectTimeout(10000);
huc.connect();
long endTime = DateProvider.getCurrentTimeMillis();
long processingTime = (endTime - startTime);
value = Long.toString(processingTime);
catch (IOException ioe)
{
processFailure("Could not establish connection. Error is: '" + ioe.getLocalizedMessage() + "'.");
}
我可以做些什么来绕过代码无法找到的证书?
编辑:我已经查看了其他线程中提供的解决方案。实现TrustManager可以打开MITM攻击。但由于我只是在ping服务器,这对我真的有影响吗?