in reply to Re^2: URL Redirect
in thread URL Redirect

That did the trick. I was missing
$ua->requests_redirectable ([]);
Thank you!

I do read the docs. I just don't understand what I am seeing, which I why I appreciate your help. (You will notice that I include my references in my code's comments)

#!/usr/bin/perl use strict; use warnings; #use diagnostics; #use diagnostics "-verbose"; use constant MaxTime1 => 20; # Seconds use LWP::UserAgent; use Term::ANSIColor qw ( BOLD BLUE RED GREEN RESET ); my $Debug = "yes"; my $RedirectUrl; my $IAm = "UrlRedirectTest.pl "; my $WebSite; sub GetUrlRedirect ( $$ ) { # Return $Url's redirected web page. Black string if none if locat +ed # References: # http://stackoverflow.com/questions/26087546/perl-print-the-redi +rected-url # http://search.cpan.org/~ether/libwww-perl-6.15/lib/LWP/UserAgen +t.pm # http://stackoverflow.com/questions/2470053/how-can-i-get-the-ul +timate-url-without-fetching-the-pages-using-perl-and-lwp # https://metacpan.org/pod/HTTP%3A%3AResponse # $r->redirects # Returns the list of redirect responses that lead up to this + response # by following the $r->previous chain. The list order is olde +st first. # In scalar context return the number of redirect responses l +eading up # to this one. # # system ('curl -s "SomeUrl" -w %{redirect_url}'); my $IAm = ( caller(0) )[3]; # Incoming: my $Url = $_[0]; my $Caller = "$_[1]" . "$IAm"; # supposting variables my $ua; my $res; # my $redirect; # my $NewUrl; $ua = LWP::UserAgent->new; $ua->timeout ( MaxTime1 ); $ua->show_progress; $ua->requests_redirectable ([]); $res = $ua->get($Url); # The parentheses around $redirect tell Perl that you want $redirec +t # to be seen as list as you in fact are only interested in the firs +t redirec if ($res->is_redirect) { my ( $NewUrl ) = $res->header('Location'); # my $NewUrl = ( $res->header('Location') ) [1]; if ( "$Debug" eq "yes" ) { print STDERR "Redirect Url = <${NewUrl}>\n"; } return ${NewUrl}; } else { print STDERR "${Caller}: ${Url} has no redirect\n"; return ""; } } $WebSite = 'http://gbis.com'; $RedirectUrl = GetUrlRedirect ( $WebSite, $IAm ); print "WebSite <$WebSite> redirects to <$RedirectUrl>\n\n"; $WebSite = 'http://google.com'; $RedirectUrl = GetUrlRedirect ( $WebSite, $IAm ); print "WebSite <$WebSite> redirects to <$RedirectUrl>\n\n"; $WebSite = 'http://usa.kaspersky.com/files/?file=kis&program=one&lang= +en&track=pu_kiskis_usen'; $RedirectUrl = GetUrlRedirect ( $WebSite, $IAm ); print "WebSite <$WebSite> redirects to <$RedirectUrl>\n\n"; END $ ./Url.Redirest.Test.pl UrlRedirectTest.pl main::GetUrlRedirect: http://gbis.com has no redire +ct WebSite <http://gbis.com> redirects to <> Redirect Url = <http://www.google.com/> WebSite <http://google.com> redirects to <http://www.google.com/> Redirect Url = <https://klamericas.s3.amazonaws.com/files/one/en/kis17 +.0.0.611en_10755.exe> WebSite <http://usa.kaspersky.com/files/?file=kis&program=one&lang=en& +track=pu_kiskis_usen> redirects to <https://klamericas.s3.amazonaws.c +om/files/one/en/kis17.0.0.611en_10755.exe>