Java Utililty Methods HttpURLConnection Create

List of utility methods to do HttpURLConnection Create

Description

The list of methods to do HttpURLConnection Create are organized into topic(s).

Method

HttpURLConnectioncreateHttpURLConnection(String urlString, int timeout)
Create an HTTP connection (GET).
URL url = new URL(urlString);
URLConnection connetion = url.openConnection();
HttpURLConnection httpConnection = null;
if (connetion instanceof HttpURLConnection) {
    httpConnection = (HttpURLConnection) url.openConnection();
    httpConnection.setInstanceFollowRedirects(true);
    httpConnection.setRequestMethod("GET");
    httpConnection.setConnectTimeout(timeout);
...
HttpURLConnectioncreateHttpURLGetConnection(String url, int timeout)
Create an HTTP GET connection with the specified URL
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();
...
HttpURLConnectiongetHttpConnection(Proxy prx, URL u, int millis)
get Http Connection
HttpURLConnection h = null;
h = (prx != null) ? (HttpURLConnection) u.openConnection(prx) : (HttpURLConnection) u.openConnection();
h.setDoOutput(true);
h.setUseCaches(false);
h.setDoInput(true);
h.setAllowUserInteraction(false);
h.setRequestProperty("Accept-Charset", C_ENC);
h.setConnectTimeout(millis);
...
HttpURLConnectiongetHttpConnection(String urlStr, Proxy proxy)
get Http Connection
URL url = new URL(urlStr);
System.out.println(urlStr + ",proxy:" + proxy);
HttpURLConnection conn = null;
if (proxy != null) {
    conn = (HttpURLConnection) url.openConnection(proxy);
} else {
    conn = (HttpURLConnection) url.openConnection();
return conn;
HttpURLConnectiongetHttpConnection(String urlStr, String charSet, Map props)
get Http Connection
URL url = new URL(urlStr);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
for (Iterator iterator = props.keySet().iterator(); iterator.hasNext();) {
    String k = (String) iterator.next();
    connection.addRequestProperty(k, props.get(k));
connection.setRequestMethod("GET");
return connection;
...
URLConnectiongetHTTPConnection(String urlString)
get HTTP Connection
final URL url = new URL(urlString);
return url.openConnection();
HttpURLConnectiongetHttpConnection(URL url)
get Http Connection
return (HttpURLConnection) url.openConnection();
HttpURLConnectiongetHttpConnection(URL url, int expectedResponseCode, int connectionTimeout)
This method creates a connection to a webpage and then reutrns the connection
int count = 0;
HttpURLConnection con = null;
do {
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    con = getHttpConnection(url);
...
HttpURLConnectiongetHttpURLConnection(@Nonnull String urlStr)
get Http URL Connection
if (!urlStr.startsWith("http://") && !urlStr.startsWith("https://")) {
    throw new IllegalArgumentException("Unexpected url: " + urlStr);
URL url = new URL(urlStr);
URLConnection conn = url.openConnection();
return (HttpURLConnection) conn;
HttpURLConnectiongetHttpURLConnection(String postUrl)
get Http URL Connection
URL url = new URL(postUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("Content-Type", "application/json");
...