2011-05-27 34 views

回答

1

你需要追逐重定向本身。

if ($response->is_redirect()) { 
    $url = $response->header('Location'); 
    # goto try_again 
} 

您可能想把它放在while循环中,并使用“next”而不是“goto”。您可能还需要记录它,限制重定向你愿意追逐,

[更新]

OK我才注意到还有一个更简单的方法来做到这一点的号码等。从LWP :: UserAgent的手册页:

 
$ua->requests_redirectable 
$ua->requests_redirectable(\@requests) 
    This reads or sets the object's list of request names that 
    "$ua->redirect_ok(...)" will allow redirection for. By default, 
    this is "['GET', 'HEAD']", as per RFC 2616. To change to include 
    'POST', consider: 

     push @{ $ua->requests_redirectable }, 'POST'; 

所以是的,也许只是这样做。 :-)

+0

看来GET请求会自动在内部重定向。所以我这样做:我的$ agent = LWP :: UserAgent-> new(env_proxy => 1,keep_alive => 1,timeout => 30,agent =>“Mozilla/4.76 [en](Win98; U) “); my $ header = HTTP :: Request-> new(GET => $ link); my $ request = HTTP :: Request-> new('GET',$ link,$ header); my $ response = $ agent-> request($ request) – AgA 2011-05-29 06:40:29

+0

是的,但您的问题使用'POST',您需要手动配置(或处理)。无论如何,很高兴你的工作。 – Nemo 2011-05-29 16:25:42

+0

我的错误是,我只需要访问网页(GET)。那么这种常见的方式适用于GET和POST。 – AgA 2011-05-31 07:58:18

相关问题