我是 Perl 的新手,但需要在我正在从事的项目中使用它。我需要做的是检查 URL 是否有 301 重定向,如果有,获取位置。以下告诉我代码但没有告诉我位置:
use strict;
use warnings;
require LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
$ua->max_redirect(0);
my $response = $ua->get('http://www.actwebdesigns.co.uk/');
if ($response->is_success) {
print $response->status_line;
print $response->progress;
}
else {
die $response->status_line;
}
有谁知道如何获取位置?
问候,
菲尔
最佳答案
$response->header
方法来自HTTP::Headers并允许您检查从您的请求返回的特定 header 。要查找 Location
header ,请使用
my $loc = $response->header( 'Location' );
关于perl - 如何在 Perl 中获取 HTTP 状态和 Location header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2126472/