[Apache-SVN] Contents of /httpcomponents/oac.hc3x/trunk/src/examples/BasicAuthenticationExample.java

[Apache-SVN] Contents of /httpcomponents/oac.hc3x/trunk/src/examples/BasicAuthenticationExample.java

55HttpClient client = new HttpClient();
56
57// pass our credentials to HttpClient, they will only be used for
58// authenticating to servers with realm "realm" on the host
59// "www.verisign.com", to authenticate against
60// an arbitrary realm or host change the appropriate argument to null.
61client.getState().setCredentials(
62new AuthScope("www.verisign.com", 443, "realm"),
63new UsernamePasswordCredentials("username", "password")
64);
65
66// create a GET method that reads a file over HTTPS, we're assuming
67// that this file requires basic authentication using the realm above.
68GetMethod get = new GetMethod("https://www.verisign.com/products/index.html");
69
70// Tell the GET method to automatically handle authentication. The
71// method will use any appropriate credentials to handle basic
72// authentication requests. Setting this value to false will cause
73// any request for authentication to return with a status of 401.
74// It will then be up to the client to handle the authentication.
75get.setDoAuthentication( true );
posted on 2012-06-28 18:09 lexus 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/lexus/archive/2012/06/28/2568555.html

发布了0 篇原创文章 · 获赞 3 · 访问量 2万+
展开阅读全文
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览