in reply to LWP, SSL, 302

LWP::UserAgent::request(...) 'usually' performs redirect 'automagically' except when request method is 'POST'.
Try sub-classing LWP::UserAgent and over riding the
redirect_ok method as suggested in docs.

mitd-Made in the Dark
'My favourite colour appears to be grey.'

Replies are listed 'Best First'.
Re: Re: LWP, SSL, 302
by blakem (Monsignor) on Aug 08, 2001 at 03:40 UTC
    Here is some ancient code of mine that did exactly that, except the purpose was to *disallow* all redirects, including GETs. Its probably just a simple tweak to reverse the logic, and allow redirects on everything including POSTs. Anyway, here is the code:

    # file: # /usr/local/perllibs/LWP/UserAgent/NoRedirects.pm # usage: # use LWP::NoRedirects; # use LWP::UserAgent; package LWP::UserAgent::NoRedirects; use base qw(LWP::UserAgent); sub new { my ($class, $base) = @_; my $parser = new LWP::UserAgent; $parser->{base} = $base; bless $parser, $class; } sub redirect_ok { return 0; } 1;

    -Blake

      I tried sub-classing LWP::UserAgent and overriding the redirect_ok method to return one everytime as blakem did in his code (but opposite) here.
      #I changed the return value sub redirect_ok { return 1; } #Now I get no page returned.


      seanbo
      OK. Here is what I did to force the redirect on the POST.
      package LWP::UserAgent::ForceRedirects; use LWP::UserAgent; use base qw(LWP::UserAgent); sub new { my ($class, $base) = @_; my $parser = new LWP::UserAgent; $parser->{base} = $base; bless $parser, $class; } sub redirect_ok { my ($self, $request) = @_; print "Redirecting to: " . $request->url() . "...\n"; return 1; } 1;
      here is the output
      C:\TEMP>perl -w bcbs.pl Redirecting to: https://XXX.XXX.XXX.XXX/?&STCO=1O3F9cqwYA2QAAB6EH0k&ST +COEND... Redirecting to: https://XXX.XXX.XXX.XXX/?&STCO=2O3F9cqwYA2QAAB6EH0k&ST +COEND...


      seanbo
Re: Re: LWP, SSL, 302
by seanbo (Chaplain) on Aug 08, 2001 at 17:34 UTC
    'GET' returns nothing. Only invalid memory refernce errors at the OS level. (not sure why that happens)

    I am going to try to sub-class LWP::UserAgent. blakem, has provided me a starting point here.

    seanbo