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方法
******************************************************************************************************************************************
作者:乔叶叶
博客地址:http://www.cnblogs.com/qiaoyeye/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
******************************************************************************************************************************************
作者:乔叶叶
博客地址:http://www.cnblogs.com/qiaoyeye/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
******************************************************************************************************************************************
浙公网安备 33010602011771号