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

HttpURLConnectiongetHttpURLConnection(String strUrl)
get Http URL Connection
URL url = new URL(strUrl);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
return httpURLConnection;
HttpURLConnectiongetHttpURLConnection(String uri, String soapAction, boolean soap12)
Sets up a connection to an HTTP endpoint
URL endPointURL = new URL(uri);
HttpURLConnection connection = (HttpURLConnection) endPointURL.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.addRequestProperty("SOAPAction", soapAction);
if (soap12) {
    connection.setRequestProperty("Content-Type", "application/soap+xml");
...
URLConnectiongetHttpUrlConnection(String url)
get Http Url Connection
try {
    URLConnection uc = new URL(url).openConnection();
    uc.connect();
    return uc;
} catch (IOException e) {
    e.printStackTrace();
    throw new RuntimeException(e);
HttpURLConnectiongetHttpURLConnection(String urlAsString)
Returns an 'optimized'/fast HttpUrlConnection
URL url = new URL(urlAsString);
HttpURLConnection hConn = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
hConn.setInstanceFollowRedirects(false);
hConn.setRequestMethod("HEAD");
return hConn;
HttpURLConnectiongetHttpUrlConnection(String urlStr)
Return URL object by given URL string, proxy is considered
HttpURLConnection conn = null;
try {
    URL url = new URL(urlStr);
    if (proxy != null) {
        conn = (HttpURLConnection) url.openConnection(proxy);
    } else {
        conn = (HttpURLConnection) url.openConnection();
} catch (Exception e) {
    return null;
return conn;
HttpURLConnectiongetHttpUrlConnection(URL url)
Returns a HttpUrlConnection for a URL pointing to an HTTP resource.
URLConnection connection = url.openConnection();
if (connection instanceof HttpURLConnection) {
    return (HttpURLConnection) connection;
} else {
    throw new IllegalArgumentException("Url is not targeted at an HTTP resource" + url);
HttpURLConnectiongetHttpURLConnection(URL url)
get Http URL Connection
if (proxy != null) {
    return (HttpURLConnection) url.openConnection(proxy);
} else {
    return (HttpURLConnection) url.openConnection();