Eduardo Martins wrote:
 HttpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new
UsernamePasswordCredentials(userName,password));

What is the similar code to set those credentials for a single request in
HttpClient 4.x?

-- Eduardo

-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-
http://emmartins.blogspot.com
http://www.redhat.com/solutions/telco


Eduardo

One can bind a different CredentialsProvider instance to the local execution context in order to override the default one:

---
HttpHost targetHost = new HttpHost("localhost", 80, "http");
DefaultHttpClient httpclient = new DefaultHttpClient();
BasicHttpContext localcontext = new BasicHttpContext();
BasicCredentialsProvider credProvider = new BasicCredentialsProvider();
credProvider.setCredentials(
        new AuthScope(targetHost.getHostName(), targetHost.getPort()),
        new UsernamePasswordCredentials("username", "password"));
localcontext.setAttribute(ClientContext.CREDS_PROVIDER, credProvider);

HttpGet httpget = new HttpGet("/");
HttpResponse response = httpclient.execute(targetHost, httpget,
  localcontext);
HttpEntity entity = response.getEntity();
if (entity != null) {
    entity.consumeContent();
}
---

Hope this helps

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to