首页 > Web开发 > 详细

httpclient进行basic auth认证

时间:2016-10-10 20:52:53      阅读:307      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!