Java URL Value Check isUrlResponding(String url)

Here you can find the source of isUrlResponding(String url)

Description

is Url Responding

License

Open Source License

Declaration

public static boolean isUrlResponding(String url) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class Main {

    public static boolean isUrlResponding(String url) {
        try {/*  w w  w  .ja v  a 2  s.  c om*/
            return isUrlResponding(new URL(url));
        } catch (MalformedURLException e) {
        }
        return false;
    }

    public static boolean isUrlResponding(URL url) {
        try {
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("HEAD");
            int code = conn.getResponseCode();
            //          System.out.println(url+" => ["+code+"]");
            //          if( code/100 == 4 ) return false;
            return code / 100 == 2;
        } catch (Exception e) {
        }
        return false;
    }
}

Related

  1. isUrlAvailable(URL url, Proxy proxy)
  2. isUrlDownWithRetries(String url, long timeoutMs, long retryDelayMs)
  3. isUrlExists(String url)
  4. isURLExists(String URLName)
  5. isUrlInJar(URL url)
  6. isUrlValid(final URL url)
  7. isUrlValid(URL url)
  8. isValid(String candidateUrl)
  9. isValid(String url)