Java HttpURLConnection Create getHttpConnection(Proxy prx, URL u, int millis)

Here you can find the source of getHttpConnection(Proxy prx, URL u, int millis)

Description

get Http Connection

License

Open Source License

Declaration

public static HttpURLConnection getHttpConnection(Proxy prx, URL u,
            int millis) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

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

public class Main {
    public static String C_ENC = "UTF-8";

    public static HttpURLConnection getHttpConnection(Proxy prx, URL u,
            int millis) throws IOException {
        HttpURLConnection h = null;
        h = (prx != null) ? (HttpURLConnection) u.openConnection(prx)
                : (HttpURLConnection) u.openConnection();
        h.setDoOutput(true);//from  w  ww  . jav a  2s  .  co  m
        h.setUseCaches(false);
        h.setDoInput(true);
        h.setAllowUserInteraction(false);
        h.setRequestProperty("Accept-Charset", C_ENC);
        h.setConnectTimeout(millis);
        return h;
    }
}

Related

  1. createHttpURLConnection(String urlString, int timeout)
  2. createHttpURLGetConnection(String url, int timeout)
  3. getHttpConnection(String urlStr, Proxy proxy)
  4. getHttpConnection(String urlStr, String charSet, Map props)
  5. getHTTPConnection(String urlString)
  6. getHttpConnection(URL url)