use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use HTTP::Cookies;
use HTTP::Cookies::Microsoft;
BEGIN { $LWP::DebugFile::outname = 'c:/ua_debug.txt' }
use LWP::DebugFile qw(+);
####
#create cookies jar to hold the cookies for this user agent
my $cookie_jar = HTTP::Cookies->new(
file => "c:/MyFolder/Cookies/lwp_cookies.dat",
autosave => 1,
);
##
##
#create cookies jar to hold the cookies for this user agent
my $cookie_jar = HTTP::Cookies::Microsoft->new(
file => "c:/Documents and Settings/owner/Cookies/index.dat",
'delayload' => 0,
);
my $ua; #user agent
$ua = LWP::UserAgent->new;
$ua->cookie_jar($cookie_jar);
$curUrl ="http://www.mysite.com/Default.aspx";
print "getting $curUrl\n";
@curContent = newGetRequest($curUrl);
sub newGetRequest() {
my $myUrl;
my $myRes;
my $myReq;
# get url to create a request from
$myUrl=@_[0];
# Create a request
$myReq = HTTP::Request->new(GET =>"$myUrl");
#pass any cookies that exsists with this request
$cookie_jar->add_cookie_header($myReq);
# pass request to user agents
$myRes = $ua->send_request($myReq);
# if response put some cookies get them
$myRes->base("http://mysite.com/");
$cookie_jar->extract_cookies($myRes); # get cookies put by the site
if ($myRes->is_success) {
print "Success in GET $myUrl" ;
return $myRes->content;
}else
{
print "Fail in GET $myUrl";
}
}