码迷,mamicode.com
首页 > Web开发 > 详细

httpclient进行basic auth认证

时间:2016-10-10 20:54:59      阅读:441      评论:0      收藏:0      [点我收藏+]

标签:

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方法

httpclient进行basic auth认证

标签:

原文地址:http://www.cnblogs.com/qiaoyeye/p/5946855.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!