develooper Front page | perl.libwww | Postings from March 2001

LWP UA Cookies problem

Steve Borruso
March 14, 2001 20:29
LWP UA Cookies problem
Message ID:

I've been trying to control loging into a website, that uses cookies,
LPW::UserAgent and HTTP::Cookies for several days now. I've read all of
the LWP doc I
could find on both modules, chased countless newsletter threads, looked
at many
examples, and have run out of options to try in my Perl script.

It appears that when I connect and receive the target  login HTML I get
an initial cookie
from the target site OK. My cookie file gets updated with initial cookie
When I POST my userid and password though, I'm returned  the login HTML
and the
headers received don't contain the cookie info for a successful login
(values are null) and
my cookie file remains unchanged. It appears that LWP isn't sending  the
initial cookie info
back to the target server when I do the login POST.

Some observations -

If I copy my real desktop Netscape browser cookie file, that was created
from manually loging into the site,
onto my website and use that as the cookie jar file when I run my CGI,
it works fine, I get logged in.

I've tried specifying both a Netscape and "regular" type cookie jar

I tried base64 encoding the password on the POST (long shot) (not an SSL

I'm running on Solaris 2.7 with an Apache web server. I forgot how to
tell what level of LWP I'm running.

My script is attached below.

Any assistance is most appreciated.

Best regards,

Here's my script -
I've done "GETS" for initial pages that probably aren't necessary before
getting to the login screen url.
The login HTML simply does a POST supplying the "nickname" and and
password along with a "return" url.

use URI::URL;
use LWP::Simple ;
use HTML::TokeParser;
use LWP::UserAgent;
use HTTP::Cookies;
use MIME::Base64;

$BV_Start_Url= '';
$BV_GetCookie_Url= '';
$BV_Continue_Url =

$CookieFile = 'xxx/xxx/...";

  print "Content-type: text/html\n\n";
  print '<html><head></head><body>'."\n";

  $ua = LWP::UserAgent->new;
  $ua->cookie_jar(HTTP::Cookies::Netscape->new(file => "$CookieFile",
autosave => 1, ));

  $res = $ua->request(HTTP::Request->new(GET => "$BV_Start_Url"));
  print $res->status_line, "\n";
  print $res->as_string, "\n";
  print $res->base, "\n";

  $res = $ua->request(HTTP::Request->new(GET => "$BV_GetCookie_Url"));
  print $res->status_line, "\n";
  print $res->as_string, "\n";
  print $res->base, "\n";

  $res = $ua->request(HTTP::Request->new(GET => "$BV_Continue_Url"));
  print $res->status_line, "\n";
  print $res->as_string, "\n";
  print $res->base, "\n";

  $res = $ua->request(HTTP::Request->new(POST => "$BV_Login_Url"));
  print $res->status_line, "\n";
  print $res->as_string, "\n";
  print $res->base, "\n";

  print '</body></html>' ;
  exit; Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About