Java URL Value Check isHttpOk(String url)

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

Description

is Http Ok

License

Open Source License

Declaration

public static boolean isHttpOk(String url) 

Method Source Code

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

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

public class Main {

    public static boolean isHttpOk(String url) {
        HttpURLConnection conn = null;
        try {//from   w ww  . ja va  2  s  . com
            URL serverUrl = new URL(url);
            conn = (HttpURLConnection) serverUrl.openConnection();
            conn.setConnectTimeout(1000 * 5);// 5s
            conn.setRequestMethod("GET");
            conn.connect();

            int state = conn.getResponseCode();
            if (state == 200) {
                return true;
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            conn.disconnect();
        }
        return false;
    }
}

Related

  1. isFileUrl(URL url)
  2. isFileURL(URL url)
  3. isFileURL(URL url)
  4. isHosting(URL url_in)
  5. isHTTP(URL url)
  6. isHttpUrl(final URI toCheck)
  7. isHttpUrl(final URL url)
  8. isHttpUrl(String in)
  9. isHttpUrl(URL url)