Java Utililty Methods URLConnection Create

List of utility methods to do URLConnection Create

Description

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

Method

HttpURLConnectioncreateConnection(final URL url, final String authValue)
Creates a new HTTP connection to the specified server.
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(0);
connection.setReadTimeout(0);
connection.setRequestMethod("GET");
connection.setRequestProperty("Authorization", authValue);
connection.setDoOutput(true);
return connection;
HttpURLConnectioncreateConnection(String method, String destinationUrl)
create Connection
URL url = null;
HttpURLConnection httpConn = null;
int code = -1;
try {
    try {
        String queryString = getQueryString();
        if (!queryString.equals("")) {
            destinationUrl = destinationUrl + "?" + queryString;
...
HttpURLConnectioncreateConnection(String processorName, String baseUrl)
create Connection
HttpURLConnection connection = (HttpURLConnection) new URL(baseUrl + "api/process/" + processorName)
        .openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
return connection;
URLConnectioncreateConnection(URL url)
create Connection
URLConnection con = url.openConnection();
con.addRequestProperty("Protocol", "HTTP/1.1");
con.addRequestProperty("Connection", "keep-alive");
con.addRequestProperty("Keep-Alive", "200");
con.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1");
return con;
URLConnectioncreateConnection(URL url)
Creates a new java.net.URLConnection object from the specified java.net.URL.
URLConnection urlConn = url.openConnection();
if (urlConn instanceof HttpURLConnection) {
    HttpURLConnection httpConn = (HttpURLConnection) urlConn;
    httpConn.setRequestMethod("POST");
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
...
StringcreateConnection(URL url)
create Connection
URLConnection connection = url.openConnection();
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
connection.setRequestProperty("User-Agent",
        "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36");
connection.addRequestProperty("Content-Type", "application/json");
connection.addRequestProperty("Content-Encoding", "gzip");
connection.addRequestProperty("Accept", "application/json");
...
HttpURLConnectioncreateConnection(URL url, Proxy proxy)
create Connection
HttpURLConnection con = (HttpURLConnection) url.openConnection(proxy);
con.setRequestProperty("User-Agent", "Hello Minecraft!");
con.setDoInput(true);
con.setUseCaches(false);
con.setConnectTimeout(15000);
con.setReadTimeout(15000);
return con;
URLConnectiongetURLConnection(String uri)
get URL Connection
URLConnection urlConn = new URL(uri).openConnection();
urlConn.setConnectTimeout(120000);
urlConn.setReadTimeout(120000);
urlConn.setRequestProperty("User-Agent",
        "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)");
return urlConn;
URLConnectiongetUrlConnection(String urlString)
get Url Connection
URL url = new URL(urlString);
URLConnection con = url.openConnection();
return con;
URLConnectiongetURLConnection(URL url)
Returns a URL connection that an input stream can be obtained from.
if (url == null) {
    throw new MalformedURLException("URL specified is null"); 
URLConnection connection = url.openConnection();
if (connection instanceof JarURLConnection) {
    connection.setUseCaches(false);
return connection;
...