Here you can find the source of getResponseCode(String urlString)
private static int getResponseCode(String urlString) throws MalformedURLException, IOException
//package com.java2s; //License from project: LGPL import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class Main { private static int getResponseCode(String urlString) throws MalformedURLException, IOException { URL u = new URL(urlString); HttpURLConnection huc = (HttpURLConnection) u.openConnection(); huc.setRequestMethod("GET"); huc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)"); huc.connect();// w w w. ja va2s . c om int responseCode = huc.getResponseCode(); huc.disconnect(); return responseCode; } }