I'm trying to use HTTP::Cookies and LWP::UserAgent to fake a real user HTTP
request.  When executing this script from a browser, I want to set the
cookies that the website normally would and load the page that the website
normally would also.  I can't get the cookie part to work.  I'm able to send
a 'fake' referer, but I'm not able to get the cookie information.  Could
someone take a look at my script and tell me what's wrong?  I'm sure it's
all messed up, but I'm so frustrated with it that I don't know what to do.
The examples I found in CPAN are terrible.


My script:

#!c:\perl -w

use strict;
use CGI::Carp qw(fatalsToBrowser);

use HTTP::Request::Common qw(GET);
use HTTP::Cookies;
use LWP::UserAgent;

my $cookieFile = "lwpcookies.txt";
my $ua = new LWP::UserAgent;

$ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; DigExt)');
my $cookie_jar = HTTP::Cookies->new( File => "$cookieFile", AutoSave =>
1, );

# the test script we are GETting prints out the referer and query string and
sets a cookie
my $req = GET 'http://www.globalnamespace.com/sample/test.pl'; #this is my
own test script
$req->push_header(REFERER => 'http://www.somesite.com/');
my $response = $ua->request($req)->as_string;
$cookie_jar->extract_cookies($response);

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

print $response , "<br>\n";

exit;



Here is my error I'm getting when running the script:

Software error:
Can't locate object method "_header" via package "HTTP/1.0 200 OK
Date: Wed, 04 Sep 2002 15:58:18 GMT
Server: Microsoft-IIS/5.0
Content-Type: text/html
Client-Date: Wed, 04 Sep 2002 15:58:18 GMT
Client-Peer: xx.xx.xxx.xxx:80
Set-Cookie: mycookie=set; domain=.globalnamespace.com; path=/;

referer = http://www.somesite.com/<br>
query string = <br>

" (perhaps you forgot to load "HTTP/1.0 200 OK
Date: Wed, 04 Sep 2002 15:58:18 GMT
Server: Microsoft-IIS/5.0
Content-Type: text/html
Client-Date: Wed, 04 Sep 2002 15:58:18 GMT
Client-Peer: xx.xx.xxx.xxx:80
Set-Cookie: mycookie=set; domain=.globalnamespace.com; path=/;

referer = http://www.somesite.com/<br>
query string = <br>

"?) at C:/Perl/site/lib/HTTP/Cookies.pm line 244.

For help, please send mail to this site's webmaster, giving this error
message and the time and date of the error.

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to