如何在Perl中获取HTTP状态和Location头?

Phi*_*son 3 perl header http

我是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;
}
Run Code Online (Sandbox Code Playgroud)

有谁知道如何获得位置?

问候,

菲尔

fri*_*edo 8

$response->header方法来自HTTP :: Headers,允许您检查从请求返回的特定标头.要查找Location标题,请使用

my $loc = $response->header( 'Location' );
Run Code Online (Sandbox Code Playgroud)