I am new to Perl and I want to write a Perl program that:
- creates an HTTP request
- sends it to any URL (e.g. http://www.google.com )
- includes a cookie in the request
- logs the http response codes in a file
I have tried 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;
}
pls tell how to set cookie in 'request' ie
how to set a cookie when we send HTTP::Request
i was expecting something like:
$request = HTTP::Request->new(GET => 'http://www.google.com/');
$ua = LWP::UserAgent->new;
$ua->new CGI::Cookie(-name=>"myCookie",-value=>"fghij");
is this possible??