Gorby has asked for the wisdom of the Perl Monks concerning the following question:

Hello Wise Monks,

What did it mean again if I get "Moved 302" when using LWP? And what should I do to fix it?

Thanks in advance.

Gorby

Replies are listed 'Best First'.
Re: Moved using LWP
by ikegami (Patriarch) on Aug 02, 2007 at 02:31 UTC

    Web servers will usually provide the address to where the resource has moved in the Location field of the response — they're probably obligated to do so — when using Moved instead of Gone.

    For GET requests, LWP will usually check for the Location field and perform the redirect by automatically fetching the document at the specified location. It doesn't do this for POST requests unless told to using LWP::UserAgent's requests_redirectable.

    I bet you are doing a POST request which results in a 302. If so, using requests_redirectable should fix your problem.

Re: Moved using LWP
by Trizor (Pilgrim) on Aug 02, 2007 at 01:52 UTC
    302 is an HTTP reply code indicating that the requested document has moved. It usually also includes where it went, and to fix it you should check the response content with LWP and find the new location of what you are looking for, then use LWP to get that. If you are using LWP::Simple you will need to switch to LWP::UserAgent to muck with the HTTP::Response object.

Re: Moved using LWP
by varian (Chaplain) on Aug 03, 2007 at 08:29 UTC
    The other answers have responded to the formal use of the move response, all good points.

    Sometimes webservers use the move response also to discourage robot web clients that put too heavy a load on the server.
    Try reach the page manually to check if you get the same response. If not, it might help (no guarantees though) to include a short delay (e.g. sleep a second) before you issue the LWP request that raised the move.