• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Apache httpClient

 
Niko Nigde
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read about what 302 means?

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

WP
 
Niko Nigde
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know what 302 means, and that was not my question.
Thank you
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The HttpClient docs even have a web page about that: http://hc.apache.org/httpclient-3.x/redirects.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic