Perl programmer for hire: download my resume (PDF).
John Bokma MexIT
freelance Perl programmer

302 Found when using LWP::UserAgent

Tuesday, August 16, 2005 | 4 comments

Sometime ago someone emailed me that when he used my phpBB remote backup program, the program reported: Login failed: 302 Found. Back then I had no time to check into it. But today I needed the program myself, and I got the same error. Strange, since the Perl program had been working for quite some time, and I couldn't remember I updated the message board software, phpBB, on the site it was supposed to backup. I did however, update to a more recent version of ActiveState Perl.

After some tests I still had no idea what was causing this problem, so I decided to ask on Usenet, in the Perl related group comp.lang.perl.misc. I got a quick answer. The site was sending a redirect (302) as a reply to the POST request, and LWP::UserAgent doesn't default follow this redirect as a reply to POST. The solution was very simple, just adding one line of Perl:

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

After this tip, posted by Brian Wakem, the Perl program worked as it should be. I even discovered that this was documented in the LWP:UserAgent module documentation. So much for me RTFM.

Related

Also today

Please post a comment | read 4 comments, latest by Justin | RSS feed