SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to find the url turned to by perl?

    I'm sending a post to an url, and after successfully sending the post, it will turn to another page, now how to find the another page url?

    #!/usr/bin/perl
    use LWP 5.64;
    my %form;
    $form{"name"} = $name;
    $form{"email"} = $email;
    $form{"grade"} = $grade;
    my $res;
    my $url = "http://www.mydomain.com/register.php";
    SIG{ALRM} = sub {print "timeout";};
    eval{
    alarm(30);
    $res = $ua->post($url, \%form);
    alarm(0);
    };

    $page_content = $res->content if $res->is_success;
    After successfully sending the post request, it will turn to something like http://www.mydomain.com/payment.php.

    I'm trying to find the page content of payment.php, however, the above script will still get the page content of register.php.

    My question now is how to detect that the request turned to payment.php and get its content then?

  2. #2
    SitePoint Member
    Join Date
    Mar 2010
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post

    I rewrote your code somewhat to comply with modern Perl standards. I hope you don't mind.
    The changes I made to make your problem work should be obvious. Feel free to ask if you don't understand something.

    Code Perl:
    #!/usr/bin/perl
     
    use strict;
    use warnings;
     
    use LWP::UserAgent;
     
    my $url = "http://www.mydomain.com/register.php";
    my %form = (
        name => $name, # where are these 3 variables initialised? This breaks strictures
        email => $email,
        grade => $grade,
    );
     
    my $user_agent = LWP::UserAgent->new( 
        timeout => 30,
        requests_redirectable => [qw/GET HEAD POST/],
    );
     
    my $response = $user_agent->post( $url, \%form );
     
    if( $response->is_success ) {
        my $page_content = $res->content;
        # do stuff
    }
    Last edited by Jawsoflife; Jun 9, 2010 at 02:09. Reason: Added strictures comment


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •