Keeping session alive using jakarta httpclient

Discussion in 'Java' started by Michael Fortin, Oct 12, 2004.

  1. 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.getResponseBodyAsStream());
    // the response is the "admin" page, I'm logged on!

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

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

    Thanks,

    Mike.
    Michael Fortin, Oct 12, 2004
    #1
    1. Advertising

  2. 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.getResponseBodyAsStream());
    > // the response is the "admin" page, I'm logged on!
    >
    > method = new GetMethod(".../action?parameter=value");
    > returnCode = client.executeMethod(method);
    > response = getStringFromInputStream(method.getResponseBodyAsStream());
    > // 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
    John C. Bollinger, Oct 12, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hoenes1
    Replies:
    0
    Views:
    372
    hoenes1
    Aug 16, 2004
  2. =?Utf-8?B?RGF2ZSBBbHZhcmFkbw==?=

    Keeping a session alive when accessing an ASP page with .Net code

    =?Utf-8?B?RGF2ZSBBbHZhcmFkbw==?=, Sep 1, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    632
    =?Utf-8?B?RGF2ZSBBbHZhcmFkbw==?=
    Sep 1, 2005
  3. Richard
    Replies:
    0
    Views:
    667
    Richard
    Apr 26, 2004
  4. Rachel
    Replies:
    0
    Views:
    836
    Rachel
    Oct 17, 2005
  5. Replies:
    1
    Views:
    618
    Hans Kesting
    Sep 19, 2008
Loading...

Share This Page