http://blog.vinodsingh.com/2008/05/proxy-authentication-in-java.html
感谢Vinod Singh先生,我找到了解决方案。
Java中的代理身份验证
普通的公司网络通过代理服务器提供Internet访问,有时还需要身份验证。可能应用程序会打开
与公司Intranet外部服务器的连接。因此,必须以编程方式进行代理身份验证。幸运的是,Java提供了一种
透明的机制来执行代理身份验证。
创建一个像下面这样的简单类-
import java.net.Authenticator;class ProxyAuthenticator extends Authenticator { private String user, password; public ProxyAuthenticator(String user, String password) { this.user = user; this.password = password; } protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(user, password.toCharArray()); }}并在您的代码打开URLConnection-之前放置这些代码行
Authenticator.setDefault(new ProxyAuthenticator("user", "password"));System.setProperty("http.proxyHost", "proxy host");System.setProperty("http.proxyPort", "port");现在,所有呼叫将成功通过代理身份验证。



