Java HttpURLConnection Create createHttpURLGetConnection(String url, int timeout)

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

Description

Create an HTTP GET connection with the specified URL

License

Open Source License

Parameter

Parameter Description
url a parameter
timeout a parameter
trustStorePws A password which is used to authenticate with iRubric server

Exception

Parameter Description

Return

An HTTP connection

Declaration

public static HttpURLConnection createHttpURLGetConnection(String url,
        int timeout) throws IOException 

Method Source Code

//package com.java2s;

import java.io.IOException;

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

public class Main {
    /**//from  w  ww  .j  ava 2 s .  c  om
     * Create an HTTP GET connection with the specified URL
     *
     * @param url
     * @param timeout
     * @param trustStorePws
     *            A password which is used to authenticate with iRubric server
     * @return An HTTP connection
     * @throws java.io.IOException
     */
    public static HttpURLConnection createHttpURLGetConnection(String url,
            int timeout) throws IOException {
        HttpURLConnection connection = null;
        URL serverAddress = null;

        serverAddress = new URL(url);

        connection = (HttpURLConnection) serverAddress.openConnection();
        connection.setRequestMethod("GET");
        connection.setDoOutput(true);
        connection.setReadTimeout(timeout);

        connection.connect();

        return connection;
    }
}

Related

  1. createHttpURLConnection(String urlString, int timeout)
  2. getHttpConnection(Proxy prx, URL u, int millis)
  3. getHttpConnection(String urlStr, Proxy proxy)
  4. getHttpConnection(String urlStr, String charSet, Map props)
  5. getHTTPConnection(String urlString)