Click to See Complete Forum and Search --> : Cookies


benny666
10-26-2003, 07:39 PM
Hello,

I have got this script to automate submitting a form to a website and getting the response back. only this site is powered by .net and when I use user agent to get even the home page it is allways getting an error and redirecting to an error page asperrorpath=...

I found out the if I turn of the cookies I get this message all the time - meaning that the site is storing id and session on my computer as a cookie.

so I added the cookie functionality to the user agent but I can't seem to have the site store the cookies on any cookie folder not the cutom lwp_cookies (see script)
and not he default microsoft cookie folder.

any suggestions???


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(+);


_____ tried that
#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,

);

_____and also that
#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";
}

}