Java HTTP Get getHttpURLConnectionByGET(String resourceURL)

Here you can find the source of getHttpURLConnectionByGET(String resourceURL)

Description

Get an object of HttpURLConnection.

License

Open Source License

Parameter

Parameter Description
resourceURL The resource URL.

Exception

Parameter Description
IOException an exception

Declaration

private static HttpURLConnection getHttpURLConnectionByGET(String resourceURL) throws IOException 

Method Source Code

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

import java.io.IOException;

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

public class Main {
    /**/*from   w  w w  . j av  a 2 s. com*/
     * Get an object of HttpURLConnection.
     * 
     * @param resourceURL
     *            The resource URL.
     * @return
     * @throws IOException
     */
    private static HttpURLConnection getHttpURLConnectionByGET(String resourceURL) throws IOException {
        HttpURLConnection conn = null;
        if (null != resourceURL && !"".equals(resourceURL.trim())) {
            URL url = new URL(resourceURL);
            conn = (HttpURLConnection) url.openConnection();
            conn.setConnectTimeout(5000);
            conn.setRequestMethod("GET");
        }
        return conn;
    }
}

Related

  1. doGet(String urlStr)
  2. doGet(String urlString)
  3. doGet(URL url, String... args)
  4. doGetRequest(String urlStr)
  5. executeGet(String targetURL)
  6. getJsonFromUrl(String url)
  7. httpGet(String httpUrl)
  8. httpGet(String url)
  9. httpGet(String url, boolean logStdout)