你可以为http请求设置默认的身份验证器,如下所示:
Authenticator.setDefault (new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication ("username", "password".toCharArray()); }});另外,如果你需要更多的灵活性,可以签出Apache HttpClient,它将为你提供更多的身份验证选项(以及会话支持等)。



