Here you can find the source of getConnection(String urlStr, boolean useProxy)
private static HttpURLConnection getConnection(String urlStr, boolean useProxy) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.net.Authenticator; import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.PasswordAuthentication; import java.net.Proxy; import java.net.URL; public class Main { private static HttpURLConnection getConnection(String urlStr, boolean useProxy) throws IOException { Authenticator authenticator = new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return (new PasswordAuthentication("fis\\haint51", "qwer4321!".toCharArray())); }/*from ww w . j av a 2 s . c om*/ }; Authenticator.setDefault(authenticator); Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.fis.vn", 8080)); if (!useProxy) { proxy = Proxy.NO_PROXY; } URL url = new URL(urlStr); HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy); return conn; } }