Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Keeping session alive using jakarta httpclient

Reply
Thread Tools

Keeping session alive using jakarta httpclient

 
 
Michael Fortin
Guest
Posts: n/a
 
      10-12-2004
Hi,

I'm using jakarta commons httpclient v3.0 and I'm trying to emulate
what I would do using a browser, like logging on to a web application
and then doing an action which requires me to be logged on.

HttpMethod method = null;
int returnCode = 0;
String response = null;
method = new GetMethod(".../login?username=mike&password=test");
returnCode = client.executeMethod(method);
response = getStringFromInputStream(method.getResponseBodyAsS tream());
// the response is the "admin" page, I'm logged on!

method = new GetMethod(".../action?parameter=value");
returnCode = client.executeMethod(method);
response = getStringFromInputStream(method.getResponseBodyAsS tream());
// the reponse is the login scren, I'm not authenticated

Can someone give me a hint on how I can acheve that?

Thanks,

Mike.
 
Reply With Quote
 
 
 
 
John C. Bollinger
Guest
Posts: n/a
 
      10-12-2004
Michael Fortin wrote:

> I'm using jakarta commons httpclient v3.0 and I'm trying to emulate
> what I would do using a browser, like logging on to a web application
> and then doing an action which requires me to be logged on.
>
> HttpMethod method = null;
> int returnCode = 0;
> String response = null;
> method = new GetMethod(".../login?username=mike&password=test");
> returnCode = client.executeMethod(method);
> response = getStringFromInputStream(method.getResponseBodyAsS tream());
> // the response is the "admin" page, I'm logged on!
>
> method = new GetMethod(".../action?parameter=value");
> returnCode = client.executeMethod(method);
> response = getStringFromInputStream(method.getResponseBodyAsS tream());
> // the reponse is the login scren, I'm not authenticated
>
> Can someone give me a hint on how I can acheve that?


The web application will use some strategy to associate different
requests together into the same session. The most common strategy is to
send a cookie in the response that it expects to see in future requests
that belong to the same session. Another possibility is that it will
expect to see some form of session ID as a query parameter; in this case
the parameter would be encoded into the URLs of all the hyperlink
targets on each page it delivers. These are not the only possibilities,
but chances are excellent that your web application is using one of
them. Figure out which one, and comply with it.


John Bollinger

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Jakarta HttpClient POST question Wil Hadden Java 11 07-01-2009 05:21 PM
Jakarta's Latest HttpClient Brent Java 2 01-20-2006 05:36 AM
Using Jakarta HTTPClient StrictSSLProtocolSocketFactory with proxy Rachel Java 0 10-17-2005 11:37 AM
problem setting proxy credentials in Jakarta HttpClient 2.0 Alex Hunsley Java 1 05-28-2004 03:02 PM
Help with Jakarta HttpClient Cookies Richard Java 0 04-26-2004 09:14 PM



Advertisments