Java HTTP Response Code getResponseCode(URL url)

Here you can find the source of getResponseCode(URL url)

Description

returns response status code for specified URL

License

Open Source License

Parameter

Parameter Description
url represents web address to check

Exception

Parameter Description
Exception an exception

Return

response code for specified URL

Declaration

public static int getResponseCode(URL url) throws Exception 

Method Source Code

//package com.java2s;

import java.net.HttpURLConnection;

import java.net.URL;

public class Main {
    /**//from  w  w  w.j  a v  a 2  s  .  c o  m
     * returns response status code for specified URL
     *
     * @param url represents web address to check
     * @return response code for specified URL
     * @throws Exception
     */
    public static int getResponseCode(URL url) throws Exception {
        HttpURLConnection.setFollowRedirects(false);
        HttpURLConnection huc = (HttpURLConnection) url.openConnection();
        return huc.getResponseCode();
    }
}

Related

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