public class MyAuth extends java.net.Authenticator {
        private String user = "";
 
        private String pass = "";
 
        public MyAuth(String username, String password) {
            user = username;
            pass = password;
        }
 
        protected java.net.PasswordAuthentication getPasswordAuthentication() {
            return new java.net.PasswordAuthentication(user, pass.toCharArray());
        }
    }
 
java.net.Authenticator.setDefault(new MyAuth("username", "password"));
然后操作HTTP或者Socket即可.
 
遇到的问题: 无法更新新的用户名和密码组合? 看来还是直接操控401协议会更好一些.

转载请注明:WebLogic Android 博客 » Java实现HTTP通信Basic认证