Java HttpURLConnection Create getHttpConnection(String urlStr, Proxy proxy)

Here you can find the source of getHttpConnection(String urlStr, Proxy proxy)

Description

get Http Connection

License

Open Source License

Declaration

private static HttpURLConnection getHttpConnection(String urlStr, Proxy proxy)
            throws MalformedURLException, IOException 

Method Source Code


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

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL;

public class Main {
    private static HttpURLConnection getHttpConnection(String urlStr, Proxy proxy)
            throws MalformedURLException, IOException {
        URL url = new URL(urlStr);
        System.out.println(urlStr + ",proxy:" + proxy);
        HttpURLConnection conn = null;
        if (proxy != null) {
            conn = (HttpURLConnection) url.openConnection(proxy);
        } else {/*from   www .j a  v  a  2s  .  co  m*/
            conn = (HttpURLConnection) url.openConnection();
        }
        return conn;
    }
}

Related

  1. createHttpURLConnection(String urlString, int timeout)
  2. createHttpURLGetConnection(String url, int timeout)
  3. getHttpConnection(Proxy prx, URL u, int millis)
  4. getHttpConnection(String urlStr, String charSet, Map props)
  5. getHTTPConnection(String urlString)
  6. getHttpConnection(URL url)
  7. getHttpConnection(URL url, int expectedResponseCode, int connectionTimeout)