首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PKIX路径构建失败:导入证书后

PKIX路径构建失败:导入证书后
EN

Stack Overflow用户
提问于 2021-08-31 12:57:28
回答 1查看 270关注 0票数 0

我有一个通过VPN访问的仪表板,可以看到数据点。但是,我们希望通过对同一仪表板链接进行REST调用并提取数据来实现这一点。但是,我遇到了以下错误。

代码语言:javascript
复制
javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

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

Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

我查看了论坛上之前提出的问题,并从URL更新了我的证书。我还有一个身份验证机制,在这个机制中我提供了访问数据的凭据,同样也是用JAVA编写的。

我正在尝试通过VPN访问仪表板链接,我的代码如下:

代码语言:javascript
复制
private static HttpsURLConnection connection; 

    public static void main(String[] args) {
        BufferedReader reader;
        String line; //every line
        StringBuffer responseContent = new StringBuffer();
        
        try {
            URL url = new URL("https://XXXXXX/XXX/XX");
            connection = (HttpsURLConnection) url.openConnection();
            connection.setAuthenticator(new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication("username", "pass".toCharArray());
                }
            });
            
            
            connection.setRequestMethod("GET");
            connection.setConnectTimeout(5000);
            connection.setReadTimeout(5000);
            
            
            int status = connection.getResponseCode();
            System.out.println(status);
            
            if(status>299) {
                reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
                while((line = reader.readLine())!=null) {
                    responseContent.append(line);
                }
            reader.close();
            }else {
                reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                while((line = reader.readLine())!=null) {
                    responseContent.append(line);
                }
                reader.close();
            }
            
        System.out.println(responseContent.toString());
            
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            connection.disconnect();
        }
    
        
    }
EN

回答 1

Stack Overflow用户

发布于 2021-08-31 13:43:36

该消息与服务器证书的PKIX验证相关。

您应该将其添加到用于运行代码的java vm的cacerts keystore中。

有关更多详细信息,请参阅this answer

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68999101

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档