Re: Need help with my code?
Dave Faraldo (dfaraldo@nocpulse.com)
Thu, 15 Mar 2001 16:37:32 -0800
> I think you can subclass the post request with one new function that
> says to follow redirects, but I haven't tried that yet.
Yup, you got it. Override LWP::UserAgent::redirect_ok with the
following, and you should be golden:
# Overloaded function to allow GET redirects following POSTs
sub redirect_ok {
my ($ua, $req) = @_;
if (uc($req->method()) eq 'GET') {
# Allow redirects on GET requests;
return 1;
} else {
# Allow GET redirects from POSTs
$req->method('GET');
return 1;
}
}
Dave Faraldo <david@nocpulse.com>
JAPH, NOCpulse, Inc.
Original message follows:
-------------------------
> Date: Thu, 15 Mar 2001 15:05:38 -0800 (PST)
> From: "Eric J. Schwertfeger" <ejs@bfd.com>
> Subject: Re: Need help with my code?
> On Thu, 15 Mar 2001, Cormac Garvey wrote:
>
> > Hi,
> > I am new to libwww. I want to use libwww to acess my bank A/C's and
> > Stocks via a client program.
>
> So am I, so I figured this one out last night.
>
> > HTTP/1.1 302 (Found) Moved Temporarily
> > Date: Thu, 15 Mar 2001 21:53:36 GMT
> > Location: /ftgw/webxpress/MainMenu
>
> ...
>
> > But unfortunately, I do not see my account information.
> >
> > Any ideas on how I can fix this.
>
> LPW does not follow redirects automatically when doing a POST. I think
> you can subclass the post request with one new function that says to
> follow redirects, but I haven't tried that yet.
>
> I don't know if you just need to keep all of your cookies and do a GET on
> the Location:, or if you need to POST to the location, though it's been my
> experience (from the CGI side) that POSTs don't redirect well with most
> web browsers, so I suspect that the GET will be good enough.
>
>