set a cookie while sending PERL HTTP::Request

Posted by dexter on Stack Overflow See other posts from Stack Overflow or by dexter
Published on 2010-03-22T05:26:45Z Indexed on 2010/03/22 5:31 UTC
Read the original article Hit count: 296

Filed under:

i have created HTTP::Request which looks like this:

#!/usr/bin/perl
require HTTP::Request;
require LWP::UserAgent;

$request = HTTP::Request->new(GET => 'http://www.google.com/');
$ua = LWP::UserAgent->new;
$ua->cookie_jar({file => "testcookies.txt",autosave =>1});

$response = $ua->request($request);
if($response->is_success){
print "sucess\n";
print $response->code;
}
else {
print "fail\n";
die $response->code;
}

now, When i send Request:

 $request = HTTP::Request->new(GET => 'http://www.google.com/');
    $ua = LWP::UserAgent->new;
    $ua->cookie_jar({file => "testcookies.txt",autosave =>1});

i want to set a cookie which might look like..

$request = HTTP::Request->new(GET => 'http://www.google.com/');
$ua = LWP::UserAgent->new;
$ua->new CGI::Cookie(-name=>"testCookie",-value=>"cookieValue");
$ua->cookie_jar({file => "testcookies.txt"});

gives error though.

AND, want to log the http response codes in the file

please help thank you

© Stack Overflow or respective owner

Related posts about perl