I am trying to query a website by submitting a form using LWP user agents and cookies
this site is using ASP.NET and IIS 5.0 and is installing cookies on the clients if I turn off the cookies
the site can't be browsed at all.
the problem is that when ever I try to send a request to the site I can't seem to get the user agent
to recieve the cookies and save it into the cookie_jar thus I get a redirect page from the server
with an error code 302 page found but object was mooved (in asp it is something like
?asperrorpath=/MainSite/Default.aspx
here is the code that I am using:
#!perl
#script uses an option to submit a get request and a post request #I will show both options
#user agent object to create a request and response use LWP::UserAgent; use HTTP::Request::Common qw(POST); use HTTP::Cookies; use HTTP::Cookies::Microsoft;
# this section use LWP:Debug file to create a ua_debug.txt file that will log the
actions of the user agent
BEGIN { $LWP::DebugFile::outname = 'c:/Marketing/bin/perl/ua_debug.txt' }
#use LWP::DebugFile;
use LWP::DebugFile qw(+); # with verbouse optionuse strict; use CGI::Carp qw( fatalsToBrowser ); use Time::localtime; use File::Basename;
#First Try #create cookies jar to hold the cookies for this user agent #my $cookie_jar = HTTP::Cookies->new( # file =>
"c:/Marketing/RealEstate/Cookies/lwp_cookies.dat", # autosave => 1, # # );
#second Try
my $cookie_jar = HTTP::Cookies::Microsoft->new(
file => "c:/Documents and Settings/BIGR2D2/Cookies/index.dat",
'delayload' => 0,
);
my $ua; #user agent $ua = LWP::UserAgent->new; $ua->cookie_jar($cookie_jar);
sub submitUrlMgr() {
my $curUrl ="http://www.elliman.com/Default.aspx"; print "getting $curUrl\n"; my @curContent = newGetRequest($curUrl);
print @curContent;
$curUrl = "http://www.elliman.com/Default.aspx"; @curContent = newPostRequest($curUrl,"elliman");
print @curContent;
}
#functions
sub newGetRequest() {
my $myUrl; my $myRes; my $myReq;
# get url to create a request from [EMAIL PROTECTED];
# 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 agent $myRes = $ua->send_request($myReq);
# if response has cookies get them
$myRes->base("http://elliman.com/");
$cookie_jar->extract_cookies($myRes); # get cookies put by the site if ($myRes->is_success) {
printToLog("Success in GET $myUrl");
return $myRes->content;
}else
{
printToLog("Fail in GET $myUrl");
}}
sub newPostRequest() {
my $myUrl; my $myCompanyParams; my $myRes; my $myReq; my $myDate;
# get url to create a request from [EMAIL PROTECTED];
# get parameters for the form $myCompanyParams = @_[1];
if ($myCompanyParams =~ /elliman/ ) {
print "post elliman\n"; $myReq = POST $myUrl ; }
#pass any cookies that exsists with this request $cookie_jar->add_cookie_header($myReq);
# Pass request to the user agent and get a response back $myRes = $ua->send_request($myReq);
$myRes->base("http://elliman.com/");
# if response has cookies get them
$cookie_jar->extract_cookies($myRes); # get cookies put by the site if ($myRes->is_success) {
print "Success in POST $myUrl";
return $myRes->content;
}else
{print "Fail in POST $myUrl";
}
}
benny
_________________________________________________________________
Surf and talk on the phone at the same time with broadband Internet access. Get high-speed for as low as $29.95/month (depending on the local service providers in your area). https://broadband.msn.com
