addProxy


gist

	public static void addProxy(String user, String pass, String host, String port) {

		if(user!= null && pass != null) {
			final String authUser = user;
			final String authPassword = pass;

			Authenticator.setDefault(
					new Authenticator() {
						public PasswordAuthentication getPasswordAuthentication() {
							return new PasswordAuthentication(
									authUser, authPassword.toCharArray());
						}
					}
			);

			System.setProperty("http.proxyUser", authUser);
			System.setProperty("http.proxyPassword", authPassword);
		}

		System.setProperty("http.proxyHost", host);
		System.setProperty("http.proxyPort", port);
	}
Anuncios
addProxy