Java HTTP Response Code getResponseCode(String urlString)

Here you can find the source of getResponseCode(String urlString)

Description

get Response Code

License

LGPL

Declaration

private static int getResponseCode(String urlString) throws MalformedURLException, IOException 

Method Source Code


//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;
    }
}

Related

  1. getResponseCode(String URL)
  2. getResponseCode(String urlS)
  3. getResponseCode(String urlString)
  4. getResponseCode(String urlString)
  5. getResponseCode(URL url)
  6. getResponseCode(URLConnection connection)