Java URL Value Check checkUrl(String url, int timeout)

Here you can find the source of checkUrl(String url, int timeout)

Description

check Url

License

Apache License

Declaration

public static int checkUrl(String url, int timeout) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;

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

public class Main {
    public static int checkUrl(String url, int timeout) {
        try {//  ww w . ja va  2s. c  o  m
            URL url2 = null;
            HttpURLConnection conn = null;
            url2 = new URL(url);
            conn = (HttpURLConnection) url2.openConnection();
            long len = conn.getContentLength();
            conn.setConnectTimeout(timeout);
            return conn.getResponseCode();
        } catch (IOException e) {
            e.printStackTrace();
            return -1;
        }
    }

    public static int checkUrl(String url) {
        return checkUrl(url, 2000);
    }
}

Related

  1. checkUrl(final String link)
  2. checkURL(String _url)
  3. checkUrl(String inputUrlString)
  4. checkURL(URL check)
  5. checkUrl(URL url, URL baseUrl)
  6. checkURLAvailable(String targetUrl)
  7. checkUrlImage(final String url)