{"id":302,"date":"2007-09-08T13:01:04","date_gmt":"2007-09-08T18:01:04","guid":{"rendered":"http:\/\/www.mccambridge.org\/blog\/2007\/09\/why-are-all-my-lwp-post-requests-returning-status-302\/"},"modified":"2022-09-11T00:40:41","modified_gmt":"2022-09-11T00:40:41","slug":"why-are-all-my-lwp-post-requests-returning-status-302","status":"publish","type":"post","link":"http:\/\/www.mccambridge.org\/blog\/2007\/09\/why-are-all-my-lwp-post-requests-returning-status-302\/","title":{"rendered":"Why are all my LWP POST requests returning status 302?"},"content":{"rendered":"
Quick tip for PERL users:<\/p>\n
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:<\/p>\n
push @{ $ua->requests_redirectable }, ‘POST’;<\/p>\n
You can also do this by hand, ala:<\/p>\n
$resp = $ua->post(…);
\nif ($resp->is_redirect) {
\n $resp = $ua->get($resp->header(“Location”));
\n}<\/p>\n