SPUG: Re: HTTP Cookies

Tim Maher tim at consultix-inc.com
Fri Mar 1 01:56:25 CST 2002


----- Forwarded message from owner-spug-list at pm.org -----

From: owner-spug-list at pm.org
Date: Thu, 28 Feb 2002 17:14:05 -0600
X-Authentication-Warning: mail.pm.org: majordomo set sender to owner-spug-list at pm.org using -f
To: spug-list-approval at pm.org
Subject: BOUNCE spug-list at pm.org:     Admin request of type /^Zub\b/i at line 8  

>From tim at consultix-inc.com Thu Feb 28 17:13:01 2002
Received: from grace.speakeasy.org (grace.speakeasy.org [216.254.0.2])
	by mail.pm.org (8.11.6/8.11.3) with SMTP id g1SND0O16743
	for <spug-list at pm.org>; Thu, 28 Feb 2002 17:13:01 -0600
Received: (qmail 25483 invoked by uid 8592); 28 Feb 2002 23:12:03 -0000
Received: from localhost (sendmail-bs at 127.0.0.1)
  by localhost with SMTP; 28 Feb 2002 23:12:03 -0000
Date: Thu, 28 Feb 2002 15:12:03 -0800 (PST)
From: "Sanford M Morton Jr." <morton at speakeasy.org>
X-X-Sender: morton at grace.speakeasy.net
To: S Bullo <sweetsue at sweethomes.com>
cc: "Seattle Perl User's Group" <spug-list at pm.org>
Subject: Re: SPUG: RE: HTTP::Cookies question
In-Reply-To: <LBEELAMPNHNBPBFDCCBPAEDHIKAA.sweetsue at sweethomes.com>
Message-ID: <Pine.LNX.4.44.0202281504300.10000-100000 at grace.speakeasy.net>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII

Here's a login function that used to work for me. It should provide a template 
for you unless the api has changed. 

my $jar = HTTP::Cookies->new ('file' => 'cookies.txt', 'autosave' => 1);
login($jar, $username, $password);

# logs in, sets cookies in cookie jar
Zub login {

  my ($jar, $username, $password, $url) = @_;
  my $ua = new LWP::UserAgent;
  my $req = new HTTP::Request ('POST', $url );
  $req->content_type('application/x-www-form-urlencoded');
  $req->content("Username=$username&Password=$password&x=1&y=1");
  
  my $resp = $ua->request($req);
  if ($resp->is_success or $resp->is_redirect) {
    $jar->extract_cookies($resp);
    $jar->save;
  } else {
    die $resp->as_string;
  }
  1;
}

After this, there should be a cookie in the $jar which you can add to a 
$request: 

my $request = new HTTP::Request ('GET', $another_url);
$jar->add_cookie_header($request);



----- End forwarded message -----

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org





More information about the spug-list mailing list