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");
boolean isConnected = (conn.getContentLength() > 0);
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:


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?

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.

This thread has been viewed 962 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 18, 2018 05:50:24.