Thank you Bill!!!!!! It worked perfect! ----- Original Message ----- From: "$Bill Luebkert" <[EMAIL PROTECTED]> To: "Alejandro Santillan Iturres" <[EMAIL PROTECTED]> Cc: <perl-win32-users@listserv.ActiveState.com> Sent: Friday, November 17, 2006 12:43 AM Subject: Re: POST request using LWP help with php forms
> Alejandro Santillan Iturres wrote: > > > I need to download a page which is password-protected (php): > > http://marketsmart-real.pcquote.com/login.php?redirectLocation=getquote.php?symbol=NDX > > > > When accessing the former page, it is requested a user and password via > > a form. > > Used AJS2 and password dosmil work fine. > > Now what I want is to emulate the manual login using LWP in order of > > getting the webpage contents. > > After inspecting the resulting form html code, I found that it has the > > following parameters: > > > > <FORM NAME="theForm" METHOD="POST"> > > <INPUT TYPE="hidden" NAME="redirectLocation" > > VALUE="getquote.php?symbol=NDX"> > > <INPUT TYPE="text" NAME="username" SIZE=20> > > <INPUT TYPE="password" NAME="password" SIZE=20> > > <INPUT TYPE="submit" VALUE="Login"> > > </FORM> > > > > > > So I've tried to get the page using LWP, passing some parameters using > > the POST method: > > > > use LWP::UserAgent; > > $ua = new LWP::UserAgent; > > $get_url="http://marketsmart-real.pcquote.com/login.php"; > > $req = HTTP::Request->new(POST=>$get_url); > > > > $req->content( redirectLocation=>"getquote.php?symbol=NDX", > > user=>"AJS2", > > password=>"dosmil"); > > > > > > $webpage=$ua->request($req)->as_string; > > print $webpage; > > > > > > The problem is that the result in $webpage says that the user or > > password are erroneous, but they are correct and work perfect by typing > > them manually. > > Am I doing something wrong when passing the parameters to the php script? > > I've also tried to pass parameters in the following form, unsuccessfully: > > $req->content("+redirectLocation='getquote.php?symbol=NDX'&+user=AJS2&+passw ord=dosmil"); > > > > Any idea? > > use strict; > use warnings; > use HTTP::Cookies; > use LWP::UserAgent; > use HTTP::Request::Common qw(POST); > > my $ua = new LWP::UserAgent; > my $cookie_jar = HTTP::Cookies->new(file => 'lwpcookies.txt', > autosave => 1, ignore_discard => 1); > $ua->cookie_jar($cookie_jar); > > my $url = 'http://marketsmart-real.pcquote.com/getquote.php?symbol=NDX'; > > my $req = POST $url, Content_Type => 'form-data', > Content => [ 'redirectLocation' => 'getquote.php?symbol=NDX', > username => 'AJS2', password => 'dosmil' ]; > my $res = $ua->request($req); > > my $content = $res->as_string; > $content =~ s/<tr[^>]*>/\n/gs; # scrub the tags etc. > $content =~ s/<[^>]*>//gs; > $content =~ s/[ \t][ \t]+/ /gs; > $content =~ s/\n\s+/\n/gs; > $content =~ s/\s+\n/\n/gs; > $content =~ s/\n\n+/\n/gs; > print $content, "\n"; > > __END__ > _______________________________________________ > Perl-Win32-Users mailing list > Perl-Win32-Users@listserv.ActiveState.com > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs