如何在java

时间:2017-05-23 03:43:10

标签: java ssl

我正在尝试使用Java查找此页面的内容。

  

https://wordassociations.net/en/words-associated-with/cessation?button=Search

但是,我收到以下错误。我该如何解决呢?

  

线程“main”中的异常javax.net.ssl.SSLHandshakeException:   sun.security.validator.ValidatorException:PKIX路径构建失败:   sun.security.provider.certpath.SunCertPathBuilderException:无法   找到所请求目标的有效证书路径

/*
 * SynonymFinder.java
 * 
 */    
import java.net.URL;
import java.util.Scanner;

public class SynonymFinder {

    public static void main(String[] args) throws Exception {
        SynonymFinder obj = new SynonymFinder();

        System.out.println(get("https://wordassociations.net/en/words-associated-with/cessation?button=Search"));
    }

    public static String get(String url) throws Exception {
        StringBuilder sb = new StringBuilder();
        for(Scanner sc = new Scanner(new URL(url).openStream()); sc.hasNext(); )
           sb.append(sc.nextLine()).append('\n');
        return sb.toString();
     }
}

1 个答案:

答案 0 :(得分:0)