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

LWP and Cookies

Thread Next
From:
Waseem Aslam
Date:
March 7, 2001 12:14
Subject:
LWP and Cookies
Message ID:
20010307201400.13255.qmail@web2906.mail.yahoo.com
Hi 

I am writing a perl script to track tranactions using
a specific shopping cart, the problem is i using
LWP::UserAgent to grab the pages and then grab the
value of the cart before payment (this is a simple
text processign thing) 

But if i use the normal site without (LWP) a cookie is
set, for the shopping cart. But when i use LWP to goto
the same page as the code shows below, no cookie is
set thus no items enter the shopping cart . 

Thus i am using the HTTP:Cookies module thingy but all
i get in the $cookie_jar is "#LWP-Cookies-1.0". 

If you can help cool, or if you know of any good
forums for perl which give quick responses e-mail and
i mean QUCIK  

Code ---- 

---------------------------------------------------- 
!/usr/local/bin/perl -w 

print "Content-type: text/html\n\n"; 

use CGI qw(:standard escapeHTML); 
use LWP::Simple; 
use HTTP::Request::Common qw(POST); 
use HTTP::Request::Common qw(GET); 
use LWP::UserAgent; 
use HTTP::Cookies; 

$pr = param('PRODREF'); 
$r = param('RANDOM'); 
$path =param('PATH'); 
$page = param('PAGE'); 
$sec = param('SECTION_BLOB'); 
$ref = param('REFPAGE'); 
$pq = param('PREVQUERY'); 

$url = "http://noneofyourbusiness.com?"; 

$cookie_file = "/whoaskedyou/cookies.txt"; 

#
------------------------------------------------------------------
# 
# Set up the User Agent 

$ua = LWP::UserAgent->new(); 
$ua->agent("Mozilla/4.51 [en]"); 

#
------------------------------------------------------------------
# 
# Set up the Cookie Jar 

$cookie_jar = HTTP::Cookies->new( file =>
$cookie_file, ,ignore_discard => 1); 
$cookie_jar->load($cookie_file); 

#
------------------------------------------------------------------
# 
# Set up the Request 
$url = $url .
"PRODREF=$pr&RANDOM=$r&PATH=$path&PAGE=$page&SECTION_BLOB=$sec";

$request = HTTP::Request->new(GET => $url); 
#$request->referer("http://www.some-referrer.com"); 
#$request->content_type('text/html'); 

# Pass our cookie(s) to the server 
$cookie_jar->load; 

$cookie_jar->add_cookie_header($request); 

#
------------------------------------------------------------------
# 
# Set up the Response 

$response = $ua->request($request); 

# Extract the Set-cookie headers from the server
response 

$cookie_jar->extract_cookies($response); 

# Save the cookie jar's state 

print $cookie_jar->as_string() ; 

#printf ("\nHere is the state of your cookie
jar:\n\n%s", 
$cookie_jar->save($cookie_file); 



print $response->as_string(); 
------------------------------------------------- 

Waseem





__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/

Thread Next


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