Java HttpURLConnection Create getHttpUrlConnection(String urlStr)

Here you can find the source of getHttpUrlConnection(String urlStr)

Description

Return URL object by given URL string, proxy is considered

License

Open Source License

Parameter

Parameter Description

Return

URL object

Declaration

public static HttpURLConnection getHttpUrlConnection(String urlStr) 

Method Source Code

//package com.java2s;

import java.net.HttpURLConnection;

import java.net.Proxy;
import java.net.URL;

public class Main {
    private static Proxy proxy;

    /**/*ww w . java2 s .c  o  m*/
     * Return URL object by given URL string, proxy is considered
     * @param urlStr: string of URL link
     * @return URL object
     */
    public static HttpURLConnection getHttpUrlConnection(String urlStr) {
        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;
    }
}

Related

  1. getHttpURLConnection(String postUrl)
  2. getHttpURLConnection(String strUrl)
  3. getHttpURLConnection(String uri, String soapAction, boolean soap12)
  4. getHttpUrlConnection(String url)
  5. getHttpURLConnection(String urlAsString)
  6. getHttpUrlConnection(URL url)
  7. getHttpURLConnection(URL url)