Java HTTP Response Code getResponseCode(String urlString)

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

Description

get Response Code

License

Apache License

Parameter

Parameter Description
urlString a parameter

Declaration

public static int getResponseCode(String urlString) 

Method Source Code


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

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)