简体   繁体   中英

Android - Error when downloading html sources: Trust anchor for certification path not found

I am downloading html source code of this webpage https://tv.zam.it/ch-Rai-1 using this:

    String content= "";
    URLConnection connection = null;
    try {
        URL url = new URL(address[0]);
        connection = (URLConnection) url.openConnection();
        Scanner scanner = new Scanner(connection.getInputStream());
        scanner.useDelimiter("\\Z");
        while (scanner.hasNext()) content += scanner.next();
        scanner.close();
    } catch (Exception ex) {
        content = ex.toString();
    }
  • on 2019 samsung phone with android 9 works fine
  • on fire tv stick (Fire OS 5.2.8.0) works fine
  • on w95 android tv box (android 7.1.2) it returns this message:

javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

I tried many of the suggested solutions but I could not make any of them change a thing. The webpage just provides tv shows info and I just need to fetch some strings from the sources, no fancy things or strict security checks required. Any suggestion?

Add your certificate(s) to a custom trust manager like described in this post: Trusting all certificates using HttpClient over HTTPS

Here are some more solution https://stackoverflow.com/a/16302527/9959901

Turns out the dns server that was added to the failing device doesn't like that site. This was the cause of the issue. Switching to another dns fixed the issue without change to the app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM