Pra quem já passou algum tempo tentando se conectar a algum sítio na Internet passando a conexão pelo proxy... aqui vai uma diquinha (besta, a proposito)
Properties systemSettings = System.getProperties();
systemSettings.put("http.proxyHost", "10.10.10.10");
systemSettings.put("http.proxyPort", "8784");
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("dominio\\usuario", "senha".toCharArray());
}
});
URL u = new URL("http://www.foo.com.br");
HttpURLConnection con = (HttpURLConnection) u.openConnection();
con.connect();
Simples assim.
Properties systemSettings = System.getProperties();
systemSettings.put("http.proxyHost", "10.10.10.10");
systemSettings.put("http.proxyPort", "8784");
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("dominio\\usuario", "senha".toCharArray());
}
});
URL u = new URL("http://www.foo.com.br");
HttpURLConnection con = (HttpURLConnection) u.openConnection();
con.connect();
Simples assim.
Nenhum comentário:
Postar um comentário