Here you can find the source of getResponseCode(String urlString)
Parameter | Description |
---|---|
urlString | a parameter |
public static int getResponseCode(String urlString)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class Main { /**/*www . jav a 2 s .c om*/ * * @param urlString * @return */ public static int getResponseCode(String urlString) { try { URL u = new URL(urlString); HttpURLConnection huc = (HttpURLConnection) u.openConnection(); huc.setRequestMethod("GET"); huc.connect(); return huc.getResponseCode(); } catch (MalformedURLException ex) { throw new RuntimeException(ex); } catch (IOException ex) { throw new RuntimeException(ex); } } }