2010-01-24 34 views
1

我是Perl的新手,但需要在我正在開發的項目中使用它。我需要做的是檢查一個URL是否有301重定向,如果有,獲取位置。下面告訴我的代碼,但不是位置:如何在Perl中獲取HTTP狀態和位置標題?

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; 
} 

沒有人知道如何獲得位置?

問候,

菲爾

回答

7

$response->header方法來自HTTP::Headers並允許您檢查從您的請求返回的特定標頭。要找到Location標頭,請使用

my $loc = $response->header('Location'); 
+0

謝謝!那很完美 – 2010-01-24 09:04:44

1

使用包含在HTTP::ResponseHTTP::Header)的頭,用$response->header

相關問題