aspose file tools*
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
Author

Apache httpClient

Niko Nigde
Greenhorn

Joined: Dec 06, 2012
Posts: 3
Hi,

I am trying to log onto http://mobile.lufthansa.com 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(
"http://mobile.lufthansa.com/mma/account.do");

HttpResponse response1 = httpclient.execute(httpGet);


try {
System.out.println(response1.getStatusLine());
HttpEntity entity1 = response1.getEntity();

EntityUtils.consume(entity1);
} finally {
httpGet.releaseConnection();
}

//working fine so far but then...
HttpPost httpPost = new HttpPost(
"http://mobile.lufthansa.com/mma/account.do");
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:
/mma/account.do;jsessionid=FAFCF62744FA4FF96CA73A7AA9F33254.portal14a?l=en

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?

http://en.wikipedia.org/wiki/HTTP_302

WP
Niko Nigde
Greenhorn

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

Joined: Oct 14, 2005
Posts: 18889
    
    8

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
Marshal

Joined: Mar 22, 2005
Posts: 42602
    
  65
The HttpClient docs even have a web page about that: http://hc.apache.org/httpclient-3.x/redirects.html


Ping & DNS - my free Android networking tools app
 
Don't get me started about those stupid light bulbs.
 
subject: Apache httpClient