Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find the final URL after all redirections in Perl?

Tags:

redirect

url

perl

Lets say I have "http://www.ritzcarlton.com" and that redirects me to "http://www.ritzcarlton.com/en/Default.htm". Is there a way in Perl to find the end url after all the redirects?

like image 411
user241126 Avatar asked Jan 06 '10 01:01

user241126


1 Answers

Using LWP will follow the redirections for you. You can then interrogate the HTTP::Request object to find out the URI it requested.

use LWP::UserAgent qw();

my $ua = LWP::UserAgent->new;

my $response = $ua->get('http://www.ritzcarlton.com');

print $response->request->uri . "\n";

Output is:

http://www.ritzcarlton.com/en/Default.htm

like image 145
mopoke Avatar answered Nov 01 '22 17:11

mopoke