Código:
package com.blogspot.rozolin.utils;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
public class ProxyUtils {
// Não é necessario instanciar essa classe
private ProxyUtils() {
}
public static void setProxy(String host, String porta,final String usuario, final String senha){
setProxy(host, porta);
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(usuario, senha
.toCharArray());
}
});
}
public static void setProxy(String host, String porta){
System.getProperties().put("http.proxySet", "true");
System.getProperties().put("http.proxyHost", host);
System.getProperties().put("http.proxyPort", porta);
}
}
No comments:
Post a Comment