Perl 如何检查302 http响应

Perl 如何检查302 http响应,perl,Perl,我正在检查重定向页面的标题,并获取302状态, 但是用我的代码,我得到了转发页面的200 OK状态。我应该怎么做才能获得重定向页面302 staus。我的代码: use LWP::UserAgent; my $ua = LWP::UserAgent->new(); my $req = HTTP::Request->new('GET','http://host.com'); my $res = $ua->request($req); print $res->status_

我正在检查重定向页面的标题,并获取302状态, 但是用我的代码,我得到了转发页面的200 OK状态。我应该怎么做才能获得重定向页面302 staus。我的代码:

use LWP::UserAgent;

my $ua = LWP::UserAgent->new();
my $req = HTTP::Request->new('GET','http://host.com');
my $res = $ua->request($req);
print $res->status_line;
$response->previous()
将为您获取链中的上一个响应


或者,如果要禁用重定向,请将
请求\u redirectable=>[]
传递给LWP::UserAgent的构造函数。

初始化$ua后,将其请求\u redirectable属性设置为undef:

$ua->requests_redirectable(undef);
这样,LWP::UserAgent将不会遵循重定向,而是在第一个请求后停止

然后,yoy可以通过以下方式获得代码(“302”、“301”等):

这是。

$ua->max\u重定向(0)将是另一种选择?
$res->code()