简体   繁体   English

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

[英]How can I get the HTTP status and Location header in Perl?

I'm new to Perl but need to use it on a project I'm working on. 我是Perl的新手,但需要在我正在开发的项目中使用它。 What I need to do is check to see if a URL has a 301 redirect and if it has, get the location. 我需要做的是检查URL是否有301重定向,如果有,请获取该位置。 The following told me the code but not the location: 以下告诉我代码但不是位置:

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

does anyone know how to get the location? 有谁知道如何获得位置?

Regards, 问候,

Phil 菲尔

The $response->header method comes from HTTP::Headers and allows you to inspect the specific headers returned from your request. $response->header方法来自HTTP :: Headers ,允许您检查从请求返回的特定标头。 To find the Location header, use 要查找Location标头,请使用

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

使用HTTP::ResponseHTTP::Header )中包含的头文件和$response->header

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM