static int getURLReturnCode(String url) { if (!url.contains("//")) url = "http://" + url; HttpURLConnection conn = null; try { conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestMethod("HEAD"); conn.setRequestProperty("X-No-Cookies", "1"); conn.getInputStream(); return conn.getResponseCode(); } catch (IOException e) { return -1; } finally { conn.disconnect(); } }