55 HttpClient 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.
61 client.getState().setCredentials(
62 new AuthScope("www.verisign.com", 443, "realm"),
63 new 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.
68 GetMethod 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.
75 get.setDoAuthentication( true );
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。