我有一个通过VPN访问的仪表板,可以看到数据点。但是,我们希望通过对同一仪表板链接进行REST调用并提取数据来实现这一点。但是,我遇到了以下错误。
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访问仪表板链接,我的代码如下:
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();
}
}发布于 2021-08-31 13:43:36
https://stackoverflow.com/questions/68999101
复制相似问题