How to save lwp::useragent state?

J

John

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
 
J

J. Gleixner

John said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top