File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes Apache httpClient Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Apache httpClient" Watch "Apache httpClient" New topic

Apache httpClient

Niko Nigde

Joined: Dec 06, 2012
Posts: 3

I am trying to log onto using apache HttpClient.

Ist there anyone out there who could give me a help or at least a hint?

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(

HttpResponse response1 = httpclient.execute(httpGet);

try {
HttpEntity entity1 = response1.getEntity();

} finally {

//working fine so far but then...
HttpPost httpPost = new HttpPost(
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("userid", "xxxx"));
nvps.add(new BasicNameValuePair("password", "xxxx"));
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
HttpResponse response2 = httpclient.execute(httpPost);

is giving me a 302 error all the time. I believe it has something to do with the session as the form method calls:

but i lack the experience to know how to handle this.

Thank you in advance!

William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Did you read about what 302 means?

Niko Nigde

Joined: Dec 06, 2012
Posts: 3
I know what 302 means, and that was not my question.
Thank you
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

So now I don't know what your question is. You say you know what the HTTP 302 response code, even though you called it an "error" in your original post. (It isn't an error code.) So given that you know what it means, you should be able to implement it by sending a new request to the location specified in the response. Did you try that?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
The HttpClient docs even have a web page about that:
I agree. Here's the link:
subject: Apache httpClient
It's not a secret anymore!