Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java PKIX路径生成失败:从自签名到自签名的API调用_Java_Spring Boot - Fatal编程技术网

Java PKIX路径生成失败:从自签名到自签名的API调用

Java PKIX路径生成失败:从自签名到自签名的API调用,java,spring-boot,Java,Spring Boot,我正在尝试从具有自签名证书的主机向具有自签名证书的另一台主机发出GET请求: @GetMapping(path = "devices") public ResponseEntity<String> getDevices(HttpServletRequest request) throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { url = &

我正在尝试从具有自签名证书的主机向具有自签名证书的另一台主机发出GET请求:

@GetMapping(path = "devices")
    public ResponseEntity<String> getDevices(HttpServletRequest request) throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
        url = "https://someurl:8448/device-data";
        return get(url);
    }

private ResponseEntity<String> get(String url) {
        RestTemplate restTemplate = new RestTemplate();
        try {
            HttpHeaders headers = new HttpHeaders();
            headers.add("Content-Type", "application/json");

            HttpEntity<String> entity = new HttpEntity<String>(headers);
            return restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
        } catch (Exception e) {
            logger.error("Failed to send GET " + url, e);
        }
        return null;
    }
我调用的API必须是自签名的,因为它是动态内部IP。
您知道如何调用此API并跳过自签名/证书问题吗?

我相信这就是您想要的(标准免责声明,在生产环境中这样做不安全)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
        at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:439)
        at java.base/sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:306)
        at java.base/sun.security.validator.Validator.validate(Validator.java:264)