问题描述:使用java爬取网站数据,报错:javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target
原因分析:您遇到的错误 javax.net.ssl.SSLHandshakeException 表示SSL握手过程失败,原因是无法找到有效的证书路径以验证目标站点的证书。这通常是由于以下原因之一引起的:
解决方法:
第一步导出证书
第二步添加到Java信任存储中
keytool -import -trustcacerts -alias mycert -file path/to/certificate.crt -keystore path/to/cacerts
path/to/certificate.crt:刚刚导出证书存放的位置
path/to/cacerts:jre底下lib底下的security文件夹下的cacerts文件(D:\soft\Java\jre\lib\security)
输入默认密码:changeit