异常:PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:

我在使用http请求https的url时候就报:异常:PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: 这个错误,搞了好好久才成功,在网上也找了很多的解决方案最后终于解决了。

我用的是导入证书的方法,让你的jdk信任你要访问的https url路径的证书

1.访问 https 域名 比如:www.baidu.com

2.点击搜索栏的小锁头

异常:PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:

3.点击证书,在点击详情,在点击复制文件

 

 

异常:PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:

4.选择途中的文件可是下载,就一直下一步就好。

异常:PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:

5.比如下载的文件名称是:huoyan.cer  我们将这个文件放到将数字证书保存到%JAVA_HOME%/jre/lib/security 中, 将该目录下的
cacerts 设置成可读写权限。
在该目录下打开cmd 运行
keytool -import -trustcacerts -alias huoyan -file huoyan.cer -keystore cacerts -storepass changeit
注意:cacerts 文件的读写权是否有