Tuesday, 7 October 2014

Test 13: Check if requested is redirected to other url

Test:
Request for a URL and check if same URL was opened or it is redirected to some other URL

Learning: 
$response->request->uri; is used to get uri. It should be used with use LWP::UserAgent


Solution:

use LWP::UserAgent qw();

my $ua = LWP::UserAgent->new;
my $response = $ua->get('http://www.google.com');
$tmp=$response->request->uri;
if($tmp eq 'http://www.google.com')
{
print "no redirection\n";
}
else
{
print "redirected to $tmp\n";
}


output snapshot:

No comments:

Post a Comment