Here you can find the source of getUrlStatus(String url)
Parameter | Description |
---|---|
url | will be checked |
public static int getUrlStatus(String url)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class Main { /**/* ww w .j a v a 2 s . co m*/ * Get the http status of url * * @param url will be checked * @return the http status of url, if any exception throwed, it will return * 0 */ public static int getUrlStatus(String url) { HttpURLConnection conn = null; try { URL u = new URL(url); conn = (HttpURLConnection) u.openConnection(); conn.connect(); return conn.getResponseCode(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e2) { e2.printStackTrace(); } finally { conn.disconnect(); } return 0; } }