[ApacheSVN] Contents of httpcomponentsoac.hc3xtrunksrcexamplesBasicAuthenticationExample.java

[ApacheSVN] Contents of httpcomponentsoac.hc3xtrunksrcexamplesBasicAuthenticationExample.java,第1张

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

55HttpClient client = new HttpClient();5657// pass our credentials to HttpClient, they will only be used for58// authenticating to servers with realm "realm" on the host59// "www.verisign.com", to authenticate against60// 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);6566// create a GET method that reads a file over HTTPS, we're assuming67// that this file requires basic authentication using the realm above.68GetMethod get = new GetMethod("https://www.verisign.com/products/index.html");6970// Tell the GET method to automatically handle authentication. The71// method will use any appropriate credentials to handle basic72// authentication requests. Setting this value to false will cause73// 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 );

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/2085110.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-07-22
下一篇 2022-07-22

发表评论

登录后才能评论

评论列表(0条)

保存