httpclient进行basic auth认证

private HttpClientContext context = HttpClientContext.create();

public void addUserOAuth(String username,String password){

        CredentialsProvider  credsProvider = new BasicCredentialsProvider();
        org.apache.http.auth.Credentials credentials = new org.apache.http.auth.UsernamePasswordCredentials(username,password);
        credsProvider.setCredentials(org.apache.http.auth.AuthScope.ANY,credentials);
        this.context.setCredentialsProvider(credsProvider);
    }

 

然后在调用httpclient.post或者get方法前,调用addUserOAuth方法

posted on 2016-10-10 18:18  乔叶叶  阅读(6964)  评论(0)    收藏  举报

导航