通过代理通过身份验证连接Java应用

时间:2019-10-01 10:12:18

标签: java

我有一个Java应用程序,该应用程序必须通过代理连接到某些地址。 这是我尝试过的:

final String authUser = "xxx";
final String authPassword = "xxx";
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","xxx");
System.setProperty("http.proxyPort","8080");

运行程序后,它给了我这个例外:

java.net.ConnectException: Connection refused: connect

我尝试通过代理连接并进行身份验证是否正确?

0 个答案:

没有答案