greenearth has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I want to hit the data of a website. Iam using WWW::Mechanize module. But unable to open the webpage. Unable to set the dynamically generated Hidden paramenters "__EVENTVALIDATION" and "__VIEWSTATE". Below is the code. Please help me.
use WWW::Mechanize; use strict; my $url = "http://reports.platou.com/FixtureReport/Pages/TankFixtures. +aspx"; my $mech = WWW::Mechanize->new(); $mech->get($url); my $content = $mech->content; #print $content; my $form = ( HTML::Form->parse( $mech->content, $url ) ); $form->action("${url}" ); my $req = HTTP::Request->new( GET => "${url}" ); my $res = $mech->request($req); my @customer_text_inputs =$form->find_input(); my $ViewState = $customer_text_inputs[0]->value; my $Validation = $customer_text_inputs[1]->value; my $fromDate = $customer_text_inputs[2]->value; my $toDate = $customer_text_inputs[3]->value; $form->push_input("hidden", { value => "$ViewState", name => '__VIEWSTATE' } ); $form->push_input( "hidden", { value => "$Validation", name => '__EVENTVALIDATION' } ); $form->push_input( "List", { value => "09-07-2010", name => 'ctl00$contentPlaceHolder$Fixtures$FromDateDr +opDown' } ); $form->push_input( "List", { value => "09-07-2010", name => 'ctl00$contentPlaceHolder$Fixtures$ToDateDrop +Down' } ); $form->push_input( "hidden", { value => "%", name => "__LASTFO +CUS" } ); $form->push_input( "hidden", { value => '', name => "__EVENTTA +RGET" } ); $form->push_input( "hidden", { value => "%", name => "__EVENTA +RGUMENT" } ); $form->push_input( "hidden", { value => "true", name => "__ASY +NCPOST" } ); $req = $mech->request($form->click()); print $req->content;
  • Comment on Unable to get set the hidden parameters "__VIEWSTATE" and "__EVENTVALIDATION" .
  • Download Code

Replies are listed 'Best First'.
Re: Unable to get set the hidden parameters "__VIEWSTATE" and "__EVENTVALIDATION" .
by sierpinski (Chaplain) on Jul 13, 2010 at 10:09 UTC
    You said you are unable to set them... what exactly is happening? Have you tried printing $form after all of the push_inputs are finished? Data::Dumper is excellent for debugging data structures, but without knowing what is happening it's difficult to suggest what to do next.
Re: Unable to get set the hidden parameters "__VIEWSTATE" and "__EVENTVALIDATION" .
by Gangabass (Vicar) on Jul 13, 2010 at 14:32 UTC

    As you can see from this JavaScript:

    <script type="text/javascript"> //<![CDATA[ var theForm = document.forms['aspnetForm']; if (!theForm) { theForm = document.aspnetForm; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } //]]> </script>
    you must set form __EVENTTARGET and __EVENTARGUMENT before submit it.

    But why are you using HTML::Form and HTTP::Request? WWW::Mechanize will make all work for you.