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

http://stackoverflow.com/questions/22448574/need-suggestion-in-tricky-form-post-data-in-a-page-using-perl

I am trying to Post and get some response data, but i am getting the same data as response even after changing the data values in the post request. i am in need of some suggestion , this is what i have tried

use strict; use warnings; use LWP::UserAgent; use WWW::Mechanize; my $mech=WWW::Mechanize->new(); my $ua = LWP::UserAgent->new; my $server_endpoint ='http://www.dartsmad.com/dartabase/darts_player_h +ead_to_head.aspx'; $mech->get($server_endpoint); my $content=$mech->content(); my $eventtarget=''; my $eventargument=''; my $lastfocus=''; my $viewstate=''; my $validation=''; if($content=~m/id="__EVENTTARGET"\s*value="([^"]*?)"/is){$eventtarget= +$1;print $1."\n\n\n\n\n\n __EVENTTARGET";sleep 2;} if($content=~m/id="__EVENTARGUMENT"\s*value="([^"]*?)"/is){$eventargum +ent=$1;print $1."\n\n\n\n\n\n __EVENTARGUMENT";sleep 2;} if($content=~m/id="__LASTFOCUS"\s*value="([^"]*?)"/is){$lastfocus=$1;p +rint $1."\n\n\n\n\n\n __LASTFOCUS";sleep 2;} if($content=~m/id="__VIEWSTATE"\s*value="([^"]*?)"/is){$viewstate=$1;p +rint $1."\n\n\n\n\n\n view_state";sleep 2;} if($content=~m/id="__EVENTVALIDATION"\s*value="([^"]*?)"/is){$validati +on=$1;print $1."\n\n\n\n\n\n__EVENTVALIDATION";sleep 2;} my $post_data = '{"__EVENTARGUMENT":'.$eventargument.',"__VIEWSTATE":' +.$viewstate.',"__EVENTTARGET":'.$eventtarget.',"__EVENTVALIDATION":'. +$validation.',"__LASTFOCUS":'.$lastfocus.',"btnComparePlayers":"Compa +re","ddlCompPlayerA":"246",ddlCompPlayerB:"259"}'; my $req = HTTP::Request->new(POST => $server_endpoint); $req->header('Content-Type: application/x-www-form-urlencoded'); $req->content($post_data); my $resp = $ua->request($req); if ($resp->is_success) { my $message = $resp->decoded_content; print "Received reply: $message\n"; open(FH,">txk.html"); print FH $message; close FH; } else { print "HTTP POST error code: ", $resp->code, "\n"; print "HTTP POST error message: ", $resp->message, "\n"; }

Replies are listed 'Best First'.
Re: Need suggestion in Post data request using perl
by Corion (Patriarch) on Mar 17, 2014 at 13:01 UTC

    Have you compared the data that a "real" browser sends against the data that your Perl script sends? I find the Firefox Live Header extension quite useful for that.

Re: Need suggestion in Post data request using perl
by Balakumar_P (Novice) on Mar 17, 2014 at 13:29 UTC
    Hi Corion, Thanks , i am not able to install the live header,but i checked it with Firebug. its was the same data. still not able to solve the issue.

      There must be a difference. If you really did verify that the data your Perl script sends is identical to the data a real browser sends, then you will have to use a network analysis tool like Wireshark to find the difference.

Re: Need suggestion in Post data request using perl
by Anonymous Monk on Mar 18, 2014 at 08:39 UTC
    Why are you mising a WWW::Mechanize object with a LWP::UserAgent object?

    Stick with WWW::Mechanize its a LWP::UserAgent subclass