Java Utililty Methods HttpURLConnection Open

List of utility methods to do HttpURLConnection Open

Description

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

Method

HttpURLConnectionopenConnection(final String urlString)
open Connection
final URL url = new URL(urlString);
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
return connection;
HttpURLConnectionopenConnection(final URL url, final String requestMethod)
open Connection
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod(requestMethod);
return connection;
HttpURLConnectionopenConnection(String url, String method, String contentType, String ssic)
open Connection
URL realURL = new URL(url);
HttpURLConnection conn = (HttpURLConnection) realURL.openConnection();
conn.setRequestProperty("User-Agent", "IIC2.0/PC 4.0.0000");
conn.setRequestProperty("Cookie", "ssic=" + ssic);
conn.setRequestProperty("Host", realURL.getHost());
conn.setRequestProperty("Accept", "*/*");
conn.setRequestProperty("Cache-Control", "no-cache");
if (contentType != null)
...
HttpURLConnectionopenConnection(URL url, Proxy proxy)
open Connection
HttpURLConnection result = (HttpURLConnection) url.openConnection(proxy);
result.setConnectTimeout(15000);
result.setReadTimeout(15000);
result.setUseCaches(false);
return result;
InputStreamopenConnectionCheckRedirects(URLConnection c)
open Connection Check Redirects
boolean redir;
int redirects = 0;
InputStream in = null;
do {
    if (c instanceof HttpURLConnection) {
        ((HttpURLConnection) c).setInstanceFollowRedirects(false);
    in = c.getInputStream();
...
HttpURLConnectiongetConnection(String url)
get Connection
try {
    return (HttpURLConnection) new URL(url.startsWith("http://") ? url : "http://" + url).openConnection();
} catch (Exception e) {
return null;
HttpURLConnectiongetConnection(String urlStr, boolean useProxy)
get Connection
Authenticator authenticator = new Authenticator() {
    public PasswordAuthentication getPasswordAuthentication() {
        return (new PasswordAuthentication("fis\\haint51", "qwer4321!".toCharArray()));
};
Authenticator.setDefault(authenticator);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.fis.vn", 8080));
if (!useProxy) {
...
HttpURLConnectiongetConnection(URL url)
get Connection
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Accept", "application/zip;text/html");
return conn;
StringgetConnectionCharset(HttpURLConnection connection)
Parse the connection content type and return the content charset
String contentType = connection.getContentType();
int charsetIndex = contentType.indexOf(CHARSET_KEY);
if (charsetIndex != -1) {
    int charsetEndIndex = contentType.indexOf(";", charsetIndex);
    if (charsetEndIndex == -1) {
        return contentType.substring(charsetIndex + CHARSET_KEY.length());
    } else {
        return contentType.substring(charsetIndex + CHARSET_KEY.length(), charsetEndIndex);
...
BufferedReadergetConnectionStream(HttpURLConnection con)
This method is used to get a connection stream from an HTTP connection.
InputStream is = con.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
return br;