Re: Need help with my code?
Randal L. Schwartz (merlyn@stonehenge.com)
15 Mar 2001 18:12:58 -0800
>>>>> "Dave" == Dave Faraldo <dfaraldo@nocpulse.com> writes:
Dave> Yup, you got it. Override LWP::UserAgent::redirect_ok with the
Dave> following, and you should be golden:
Dave> # Overloaded function to allow GET redirects following POSTs
Dave> sub redirect_ok {
Dave> my ($ua, $req) = @_;
Dave> if (uc($req->method()) eq 'GET') {
Dave> # Allow redirects on GET requests;
Dave> return 1;
Dave> } else {
Dave> # Allow GET redirects from POSTs
Dave> $req->method('GET');
Dave> return 1;
Dave> }
Dave> }
Of course, overriding really only makes sense if you think someone
else in the same program needs the documented behavior. I found it
much easier to just do this:
use LWP::UserAgent;
BEGIN { *LWP::UserAgent::redirect_ok = sub { 1 } }
Don't subclass. Patch.
But then, I'm perverse. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!