javax.net.ssl.SSLHandshakeException:在Raspberry Pi上运行Java程序时出错

时间:2019-02-03 19:31:01

标签: java raspberry-pi

我正在使用Java使用以下代码从网页中读取内容:

import java.net.*;
import java.io.*;

public class URLReader {
public static void main(String[] args)  throws Exception {

    URL oracle = new URL("http://www.example.com/");
    BufferedReader in = new BufferedReader(
    new InputStreamReader(oracle.openStream()));

    String inputLine;
    while ((inputLine = in.readLine()) != null)
        System.out.println(inputLine);
    in.close();
}
}

当我在Windows pc上运行带有eclipse的代码时,它运行良好,但是当我尝试在树莓派上运行它时,出现此错误:

javax.net.ssl.SSLHandshakeException:     sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid     certification path to requested target

我认为这意味着Java不信任该网站,但是我在任何地方都找不到解决方案。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

按此处所述更新Java即可解决问题

https://www.raspberrypi.org/forums/viewtopic.php?t=200232