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 = [COLOR=“Red”]“http://www.mydomain.com/register.php[/COLOR]”;
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?

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.


#!/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
}