The original Java code:
Code: Select all
try {
HttpURLConnection.setFollowRedirects(false);
// note : you may also need
// HttpURLConnection.setInstanceFollowRedirects(false)
HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection();
con.setRequestMethod("HEAD");
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
} catch (Exception e) {
e.printStackTrace();
return false;
}
Code: Select all
function URLisValid(url) {
try {
var url=new java.net.URL(url);
var socket=new java.net.Socket(url.getHost(),443);
var httpCon=new java.net.HttpURLConnection(url.openConnection());
httpCon.setRequestMethod("HEAD");
alert("Resp code=" + httpCon.getResponseCode());
return (httpCon.getResponseCode() == java.net.HttpURLConnection.HTTP_OK);
} catch (e) {
alert("Error 1 " + e);
return false;
} finally {
try {
socket.close();
} catch(e) {
alert("Error 2 " + e);
return false;
}
}
return true;
}
Code: Select all
Error 1 JavaException: 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