// null = online, Throwable = offline public static Throwable checkIfHttpServerIsOnline(String serverName) { try { String url = serverName.startsWith("http") ? serverName : "http://" + serverName + "/"; //HttpURLConnection.setFollowRedirects(false); // note : you may also need // HttpURLConnection.setInstanceFollowRedirects(false) HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setRequestMethod("HEAD"); int responseCode = con.getResponseCode(); //print("Response code for " + url + ": " + responseCode); // If we came this far, assume server is online. return null; //return (con.getResponseCode() == HttpURLConnection.HTTP_OK); } catch (Exception e) { return e; } }