Search code examples
androidurlconnectionhttpconnection

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?


Solution

  • 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.