in reply to Trying to Copy Live Http Replay

At least, you're not sending the cookie the browser sends. I recommend comparing what your Perl script sends and what the browser sends, by use of Wireshark, or by using LWP::Debug.

Replies are listed 'Best First'.
Re^2: Trying to Copy Live Http Replay
by sstevens (Scribe) on Mar 12, 2010 at 17:21 UTC
    Using Wireshark, I found that \r\n is being converted to %5Cr%5Cn ... any thoughts how to stop that from happening?

      Use interpolating strings, or better, don't try to add \r\n yourself, as HTTP::Headers should format your headers anyway.

      1) you will definitelypossibly need the cookies. You can either manually add a cookie header with the value listed, or you can use a cookie jar.

      2) Try backing out from using the ua->post method to creating a post from HTTP::Request::Common so you can interact with and examine it.

      3) note that the outgoing request was text/plain. No URL encoding was done.

      Turns out you just need it in the format it wants, and will accept text/plain or x/www-form-encoded content.

      #!/usr/bin/perl use warnings; use strict; use HTTP::Request::Common; use LWP::UserAgent; use Data::Dumper; my %fields = ( "LeagueID" => "9\r\n", "GameDate" => "3-2-2010\r\n", "Season" => "2009-2010\r\n", "Refresh" => "false\r\n", "LastUpdateTime" => "01-01-1900\r\n", "type" => "Matchups\r\n", "RefreshStartTime" => "11-2-2010-1268372427240\r\n", "Week" => "\r\n", "conferenceID" => "", ); my $robot = LWP::UserAgent->new; use HTTP::Request::Common; my $url = 'http://scores.covers.com/ajax/SportsDirect.Controls.LiveScoresC +ontrols.Scoreboard,SportsDirect.Controls.LiveScoresControls.ashx?_met +hod=UpdateScoreboard&_session=no'; my $post = POST $url , \%fields; # $post would be url-encoded # 'content-type' => 'application/x-www-form-urlencoded', # print Dumper $post; my $content = qq{LeagueID=9\r\nGameDate=3-2-2010\r\nSeason=2009-2010\r +\nRefresh=true\r\nLastUpdateTime=01-01-1900\r\ntype=Matchups\r\nRefre +shStartTime=12-2-2010-1268408433293\r\nWeek=\r\nconferenceID=}; # your target url appears to accept either of these my $post2 = POST $url, Content => $content; #my $post2 = POST $url, 'content-type' => 'text/plain', Content => $co +ntent; print Dumper $post2; print Dumper $robot->request( $post2);
      at least I assume this is the sort of output you were expecting:
      '_content' => '{\'LeagueID\':9,\'League\':\'NBA\',\'GameDate\':\'3-2- +2010\',\'Season\':\'2009-2010\',\'Week\':\'\',\'GameResponseList\':[] +,\'LastUpdateTime\':\'01-01-1900\',\'RefreshStartTime\':\'12-2-2010-1 +268408433293\',\'Refresh\':true,\'PageType\':\'Matchups\',\'ScoreBoar +dHTML\':\'<div id="Scoreboard_9"><table class="scoreboard" border="0" +>\\r\\n <tr>\\r\\n <td class="scoreboard-left"><div + id="Game_9_781166" class="game-box"><span class="activetab" id="In_G +ame_Status_9_781166">Final</span><div class="soright" id="Title_9_781 +166">Boston at Detroit</div><span class="pick_button"><a href="http:/ +/contests.covers.com/sportscontests/makepicks.aspx?sportID=9&EventID= +781166"><img src="http://images.covers.com/scores/general/pick.gif" a +lign="absmiddle" alt="contest pick" border="0"
        I was so close! I had gotten to the same idea, but was wrapping '' around the content instead of qq{}! Thanks so much!