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

LWP UA Cookies problem

From:
Steve Borruso
Date:
March 14, 2001 20:29
Subject:
LWP UA Cookies problem
Message ID:
3AB04213.3BFC89E1@stny.rr.com
Greetings,

I've been trying to control loging into a website, that uses cookies,
with
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
data.
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
format.

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

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,
Steve

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= 'http://www.bidville.com';
$BV_GetCookie_Url= 'http://www.bidville.com/loginstatus.cfm';
$BV_Continue_Url =
'http://www.bidville.com/login.cfm?return=http%3A%2F%2Fbidville%2Ecom%2F';

$BV_Login_Url=
'http://www.bidville.com/login.cfm?nickname=xxxx&password=xxxx';
$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, ));
  $ua->agent('Mozilla/4.0');

  $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;







nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About