本人出于兴趣开发一个关于steam信息查询的小程序时,为获取steam信息通过HttpClient访问官方的api接口时会因为没有ssl证书导致后台报异常
异常:sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
后查询资料后发现可以设置信任所有证书,绕过验证服务端的证书状态
下为具体代码,我使用的是GET请求,POST请求也可以使用。
需要配置的pom.xml
<!-- RestTemplate 依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- org.apache.http依赖-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependenc