[Logo]
Forums Register Login
HttpURLConnection locks up on connect()
public static boolean isReachableURL(URL url)
throws MalformedURLException, IOException, Exception {
System.out.println("Testing to see if URL connects");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
System.out.println("Created HttpURLConnection object");
conn.connect();
System.out.println("connecting..");
boolean isConnected = (conn.getContentLength() > 0);
System.out.println("disconnecting..");
conn.disconnect();
System.out.println("disconnected");
return isConnected;
}

I am trying to simply determine if a URL provided is a "reachable URL", if so, return true, else, return false.

On most URLs I have no problem distinguishing reachable from unreachable, but if you try something like this:

http://blah.com

It will lock up tight as a drum and I have to break into Windows Task Manager to stop the process as it runs as an infinite loop at this point.

So how can I reliably determine if a URL is reachable or unreachable?

Thanks
Phil
Please use UBB code tags (read this) when posting code to preserve the formatting.

Also, as this really has nothing to do with JSP per se, it's been moved to the Internet Protocols forum as a more appropriate location.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Nov 18, 2017 14:32:56.