Monthly Archives: September 2007

Why are all my LWP POST requests returning status 302?

Quick tip for PERL users:

LWP does not redirect on POST requests by default. If you are trying to POST to a page which replies with a redirect, e.g., authenticating with a webform or somesuch, you need to enable redirects via this line:

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

You can also do this by hand, ala:

$resp = $ua->post(…);
if ($resp->is_redirect) {
$resp = $ua->get($resp->header(“Location”));

Originally found via: this news post