0

I am trying to send a GET request to the web server from the android device, the server is having digest authentication enabled, I am able to authenticate using following sort of code,

HttpHost host = new HttpHost(urlObj.getHost(), -1, null);
CredentialsProvider cp = new BasicCredentialsProvider();
cp.setCredentials(scope, creds);
HttpContext credContext = new BasicHttpContext();
credContext.setAttribute(ClientContext.CREDS_PROVIDER, cp);

Now my problem is every time when I call httpClient.execute() function it first send request without authentication header and then second time with proper headers. So is there any way I can instruct HttpClient to send authentication details by default?

One way is to store the last sent request but, I am also not able to get the last sent request. Any suggestion on this?

Thanks in advance.

pragnesh
  • 1,212
  • 7
  • 17
  • I go the solution, I used the PreemptiveAuth class and most important thing is, I am now creating only one connection to server and reusing the same for all requests. – pragnesh Oct 11 '11 at 13:17

1 Answers1

0

You may use HttpURLConnection to save all the params you need. I use it and display my source code here.

url_connection is defined like that

private HttpURLConnection url_connection; // WebService Connection

url_connection= (HttpURLConnection) new URL(your_url_server).openConnection();

url_connection.setRequestMethod("POST"); url_connection.setDoInput(true); url_connection.setDoOutput(true); ....

Community
  • 1
  • 1
Dsandre
  • 312
  • 1
  • 5
  • 14