Java中http请求添加 Basic authentication

/ HTTPJava / 0 条评论 / 1660浏览
//The easiest way to tell Java to use HTTP Basic authentication is to set a default Authenticator:
    private void authenticator() {
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication (RPC_USER, RPC_PASSWORD.toCharArray());
            }
        });
    }