How to ignore/accept/avoid SSLHandshakeException while trying to check for broken links?



  • I'm trying to verify if a link is throwing response code other than 200. Link that I'm trying to verify is https:// and after process has run, it throws this error -- "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" Code that I'm using -- URL h1 = new URL(crazyLink) HttpURLConnection huc1 = (HttpURLConnection) h1.openConnection(); huc1.setRequestMethod("GET"); huc1.connect(); if(huc1.getResponseCode() == 200){ System.out.println("Passed"); }else{ System.out.println("Failed"); } I've tried changing FirefoxProfile to ignore ssl but it didn't work -- firefoxProfile profile=new firefoxProfile(); Profile.setAssumeUntrustedCertificateIssuer(false); driver=new firefoxDriver(profile); Any help will be highly appreciate. Thank you in advance.



  • The exception is not related to HTTP Basic Authentication, i.e., is not about missing authentication credentials. This also has nothing to do with broken links. This bizzarre exception message is saying that in your truststore you do not have certificate of the Web site you want to connect to, so simply that you do not trust this site. Now the solution depends on which of your code excerpts we're talking about. For the first you should use HttpsURLConnection instead of HttpURLConnection, because you're trying to connect to SSL-protected URL. Then you should: download site's certificate and add it to your local trusstore, or use trust manager that does not validate certificate chains for SSL sockets. For the second code which uses WebDriver it may depend on which library version are using. So which one are you using?



Suggested Topics