hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Blechert <blech...@ta-hameln.de>
Subject Basic Authentification on httpclient 4.0.1
Date Mon, 02 Aug 2010 15:08:43 GMT
  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/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.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: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message