Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Trying to Copy Live Http Replay

by spazm (Monk)
on Mar 12, 2010 at 17:56 UTC ( #828342=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Trying to Copy Live Http Replay
in thread Trying to Copy Live Http Replay

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"


Comment on Re^3: Trying to Copy Live Http Replay
Select or Download Code
Re^4: Trying to Copy Live Http Replay
by sstevens (Scribe) on Mar 12, 2010 at 18:23 UTC
    I was so close! I had gotten to the same idea, but was wrapping '' around the content instead of qq{}! Thanks so much!
      using "" and qq{} should be nearly equivalent(1). In both cases you need to be careful to not include additional whitespace.

      Here are four equivalent declarations using "" and qq{}.

      #/usr/bin/perl use strict; use warnings; use Test::More tests =>4 ; my $a1 = qq{a\r\nb\r\nc\r\n}; my $a2 = qq{a\r b\r c\r }; my $b1 = "a\r\nb\r\nc\r\n"; my $b2 = "a\r b\r c\r\n"; is( $a1, $a2, "a1 and a2 are the same"); is( $b1, $b2, "b1 and b2 are the same"); is( $a1, $b1, "a1 and b1 are the same"); is( $a2, $b2, "a2 and b2 are the same"); __END__ 1..4 ok 1 - a1 and a2 are the same ok 2 - b1 and b2 are the same ok 3 - a1 and b1 are the same ok 4 - a2 and b2 are the same

      1 -- except for the semantics used for escaping, qq will escape double-quotes in the string.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://828342]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-07-12 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls