Here you can find the source of getHttpConnection(String urlStr, Proxy proxy)
private static HttpURLConnection getHttpConnection(String urlStr, Proxy proxy) throws MalformedURLException, IOException
//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; } }