by, 02-24-2012 at 07:03 PM (2120 Views)
Within HttpClient, preemptive authentication can be enabled. HttpClient sends the response of basic authentication before unauthorized is given by server, in preemptive authentication mode. This will be reducing overhead for connection making.
To enable it, use this code.
For preemptive authentication, default credentials are required to be set for proxy host or target. Preemptive authentication will become ineffective in case default credentials are not been provided.Java Code:client.getParams().setAuthenticationPreemptive(true);
This process is explained by given code.
Java Code:Credentials defaultcreds = new UsernamePasswordCredentials("username", "password"); client.getState().setCredentials(new AuthScope("myhost", 80, AuthScope.ANY_REALM), defaultcreds);