对“https://jsonplaceholder.typicode.com/users”的 GET 请求出现 I/O 错误:

时间:2021-06-15 03:26:03

标签: spring-boot spring-mvc microservices spring-resttemplate

下面是restController。我正在尝试访问 JsonPlaceholder api,它在浏览器和邮递员中给出响应,但是当我尝试通过 restemplate 访问 url 时,它显示以下错误。 “https://jsonplaceholder.typicode.com/users”的 GET 请求上的 I/O 错误:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效认证路径;嵌套异常是 javax.net.ssl.SSLHandshakeException:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效认证路径

@RestController
public class CowinController {
    @Autowired
    private RestTemplate restTemplate;
    
@RequestMapping(path = "/cowin")
public RestTemplate getData()
    HttpHeaders headers = new HttpHeaders();
    String jsonPlaceholder = **"https://jsonplaceholder.typicode.com/users";**
    HttpEntity<String> requeEntity = new HttpEntity<String>(headers);
    ResponseEntity<Object> responseEntity = restTemplate.exchange(jsonPlaceholder,HttpMethod.GET,requeEntity,Object.class);
    Object response = responseEntity.getBody();
}

0 个答案:

没有答案
相关问题