windows系统中,java环境是jdk1.8.0,以前通过https://xxx.xxx.cn/open_api/authenticatin/get_access_token?key=xxx&secret=xxx访问第三方时能获取正确数据,现在调用时程序报错: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
分析原因:
目标服务器更换了证书,而新证书的根证书或中间证书不在Java的信任库中
解决措施:
1、访问 https://xxx.xxx.cn
在浏览器中。点击地址栏的图标 > "证书" > "详细信息" > "复制到文件" _.xxx.xxx.crt
2、使用 keytool 导入:cmd复制 keytool -import -alias dataha_cert -keystore "%JAVA_HOME%\jre\lib\security\cacerts" -file "_.xxx.xxx.crt"
3、重启程序