java程序中访问https时,报 PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

在java中使用https访问数据时报异常:

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

需要使用keytool工具,将对应域名的证书导入到jdk的cacerts中,这个证书可以是*.crt,*.cer等证书

cacerts包含了很多CA证书,位置在Java的安装目录: Java\jdk1.8.0_181\jre\lib\security\cacerts

执行如下命令,可将证书导入到cacerts中,使其成为可信证书:

cd D:\IDE\Java\jdk1.8.0_181\jre\lib\security
keytool -importcert -alias httpfs -keystore cacerts -file D:\IDE\Java\jdk1.8.0_181\jre\lib\security\ssl.cer

需要输入cacerts证书库密码:changeit

如果没有证书,可以使用Chrome浏览器访问https域名,下载对应的证书,详情请参照:https://blog.csdn.net/qq_31222053/article/details/94174506

 

posted @ 2019-11-18 17:22  七星6609  阅读(7960)  评论(0编辑  收藏  举报