Thank you. It works. :-)

I'll try to help a bit...we use 3.1, but the high level answer here will likely 
be the same.  Everyone else that answers will want a wire log - this will give 
the for-sure answer as to why your code isn't sending the Basic Auth.

The most likely reason is that the "realm" you've associated the credentials with isn't 
actually correct - you have used "www.example.com, 80" below.  I know that is just a 
filler and that your real code isn't using that realm.

For an easy test change from a specific realm to the ANY_REALM and try your 
code.  If it works then it is 100% because the realm you've provided isn't the 
correct value.

...Pete

-----Original Message-----
From: Christian Blechert [mailto:[email protected]]
Sent: Monday, August 02, 2010 8:09 AM
To:[email protected]
Subject: Basic Authentification on httpclient 4.0.1

  Hey Guys.
I'm using httpclient 4.0.1 to access a basic auth protected Website. But
it works not really...

My source code follows this example:
http://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.0.x/ht
tpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasic
Authentication.java

===========================

DefaultHttpClient client = new DefaultHttpClient();

UsernamePasswordCredentials creds = new
UsernamePasswordCredentials("username", "password");
client.getCredentialsProvider().setCredentials(new
AuthScope("www.example.com", 80), creds);

BasicHttpContext localcontext = new BasicHttpContext();
BasicScheme basicAuth = new BasicScheme();
localcontext.setAttribute("preemptive-auth", basicAuth);
client.addRequestInterceptor(new PreemptiveAuth(), 0);

HttpGet httpget = new HttpGet("http://www.example.com/dosomething.html";);
HttpResponse response = client.execute(httpget);

===========================

The code will executed. But the credentials will be not send.

The class PreemptiveAuth can be found in the example.
What is wrong? Any ideas?

Thanks for your help. :-)

Greetings,
Christian Blechert.



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



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

Reply via email to