Cookies are not saved to cookie_jar

B

benny s.

Hello,<p>

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

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

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

any suggestions???<br>

<br><br>
use LWP::UserAgent;<br>
use HTTP::Request::Common qw(POST);<br>
use HTTP::Cookies;<br>
use HTTP::Cookies::Microsoft;<br>
<br><br>

BEGIN { $LWP::DebugFile::eek:utname = 'c:/ua_debug.txt' }<br>
use LWP::DebugFile qw(+); <br>
<br><br>

_____ tried that <br>
#create cookies jar to hold the cookies for this user agent<br>
my $cookie_jar = HTTP::Cookies->new( <br>
file =>
"c:/MyFolder/Cookies/lwp_cookies.dat",<br>
autosave => 1, <br>

);<br>
<br>
_____and also that<br>
#create cookies jar to hold the cookies for this user agent<br>
my $cookie_jar = HTTP::Cookies::Microsoft->new(<br>
file => "c:/Documents and
Settings/owner/Cookies/index.dat",<br>
'delayload' => 0,<br>
);<br>
<br><br>

my $ua; #user agent<br>
$ua = LWP::UserAgent->new;<br>
$ua->cookie_jar($cookie_jar);<br>
<br><br>

$curUrl ="http://www.mysite.com/Default.aspx";<br>
print "getting $curUrl\n";<br>
@curContent = newGetRequest($curUrl);<br>
<br><br>

sub newGetRequest() {<br>
<br>
my $myUrl;<br>
my $myRes;<br>
my $myReq;<br>

# get url to create a request from<br>
$myUrl=@_[0];<br>
<br>
# Create a request<br>
$myReq = HTTP::Request->new(GET =>"$myUrl");<br>
<br>
#pass any cookies that exsists with this request <br>
$cookie_jar->add_cookie_header($myReq);<br>
<br>
# pass request to user agents<br>
$myRes = $ua->send_request($myReq); <br>
<br>
# if response put some cookies get them<br>
$myRes->base("http://mysite.com/");<br>
$cookie_jar->extract_cookies($myRes); # get cookies put by the
site<br>
<br>
if ($myRes->is_success) {<br>
print "Success in GET $myUrl" ;<br>
return $myRes->content;<br>
}else<br>
{ <br>
print "Fail in GET $myUrl"; <br>
}<br>
<br>
}<br>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top