How to save lwp::useragent state?

Discussion in 'Perl Misc' started by John, Apr 28, 2004.

  1. John

    John Guest

    Hello. I have a perl script that uses a LWP::Useragent
    to retrieve data from a password protected page. Here is
    how I have set the authentication:

    my $uagent = new LWP::UserAgent;
    $uagent->agent('My Cool Browser');
    $uagent->conn_cache(LWP::ConnCache->new());
    $uagent->cookie_jar(HTTP::Cookies->new('file'=>cookies1',
    'autosave'=>1,));
    $uagent->credentials('www.mywebsite.com:80, 'test account', 'john'=>
    'john123');
    $myurl = 'http://www.mywebsite.com/secret';
    $uagent->get($myurl);
    print $uagent->content();

    The above code works, but after doing a network trace it seems that
    the user agent is logging in (HTTP authorization) each time it tries
    to access the page (even if the page has been accessed before during
    the same program session). A regular web browser does not behave like
    this though -- once you log in, it does not try to keep logging in
    during the same browser session. My question: is there any way to make
    this behave a like a regular browser? Thanks.

    John
     
    John, Apr 28, 2004
    #1
    1. Advertising

  2. John

    J. Gleixner Guest

    John wrote:

    > The above code works, but after doing a network trace it seems that
    > the user agent is logging in (HTTP authorization) each time it tries
    > to access the page (even if the page has been accessed before during
    > the same program session). A regular web browser does not behave like
    > this though -- once you log in, it does not try to keep logging in
    > during the same browser session. My question: is there any way to make
    > this behave a like a regular browser? Thanks.


    This has nothing to do with perl, read up on HTTP authentication. A web
    server is "stateless", meaning authentication has to happen on each
    request. The browser does it for you, automagically. I'd think your
    "network trace", using a browser, would have shown that.
     
    J. Gleixner, Apr 28, 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. La Jesus
    Replies:
    9
    Views:
    1,337
    Gunnar Hjalmarsson
    Oct 27, 2003
  2. Chandra

    Problem with LWP::USERAGENT

    Chandra, Feb 25, 2004, in forum: Perl
    Replies:
    0
    Views:
    510
    Chandra
    Feb 25, 2004
  3. Vinay Gupta
    Replies:
    2
    Views:
    1,123
    Michael Schlenker
    Jul 27, 2004
  4. Playker
    Replies:
    0
    Views:
    516
    Playker
    Feb 24, 2005
  5. Replies:
    13
    Views:
    2,770
    Arne Vajhøj
    Mar 18, 2008
Loading...

Share This Page