public class Prueba{ public static void main(String[] args) { try { String ipProxy = ""; String portProxy = ""; String userProxy = ""; String passProxy = ""; System.setProperty("http.proxyHost", ipProxy); System.setProperty("http.proxyPort", portProxy); URL url = new URL("http://www.google.es"); URLConnection uc = url.openConnection (); String encoded = new String (Base64.encode(new String(userProxy + ":" + passProxy ).getBytes())); uc.setRequestProperty("Proxy-Authorization", "Basic " + encoded); uc.connect(); InputStream is = uc.getInputStream(); System.out.println(getStringFromInputStream(is)); } catch (Exception e) { e.printStackTrace(); } } public String getStringFromInputStream(InputStream is){ // TODO return null; } }
public final static Boolean USE_PROXY = false; public final static Boolean IS_PROXY_AUTH = false; public final static String PROXY_USER = ""; public final static String PROXY_PASSWORD = ""; public final static String PROXY_SERVER =""; public final static Integer PROXY_PORT = null; private void configureConnection() { if(USE_PROXY) { System.setProperty("http.proxyHost", PROXY_SERVER); System.setProperty("http.proxyPort", Integer.toString(PROXY_PORT)); if (IS_PROXY_AUTH) { Authenticator.setDefault(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(PROXY_USER, PROXY_PASSWORD.toCharArray()); } }); } else { Authenticator.setDefault(null); } } }