Perl:LWP :: UserAgent总是为重定向的URL返回代码200

Nov*_*der 8 perl http lwp-useragent

我有一个简单的网址,它有302临时性.转到另一页.

如果URL返回代码200(对于OK)以检索它并且如果返回除200之外的其他内容,则尝试进入.

我的代码:

my $ua = LWP::UserAgent->new( env_proxy => 1,keep_alive => 1, timeout => 30, agent => "Mozilla/4.76 [en] (Win98; U)");
my $response = $ua->get( $currenturl);
print $response->code;
Run Code Online (Sandbox Code Playgroud)

ALWAYS上面的代码返回200,即使它是302.我在Firefox中使用FireBug测试了头部响应.该URL在FireBug的Net模块中返回"302 Moved Temporarily".但是perl上面的代码返回200.为什么?

Ale*_*lev 19

LWP :: UserAgent自动遵循HTTP重定向.您可以通过将max_redirect选项设置为to 来禁用此类行为0.

my $ua = LWP::UserAgent->new( max_redirect => 0, env_proxy => 1,keep_alive => 1, timeout => 30, agent => "Mozilla/4.76 [en] (Win98; U)");
my $response = $ua->get( $currenturl);
print $response->code;
Run Code Online (Sandbox Code Playgroud)