![]() |
LWP and 302 redirects
Hi
I'm having trouble with LWP and 302 redirects. I found the "$ua->requests_redirectable" parameter in the LWP documentation but it still doesn't work. Here's my code: use LWP::UserAgent; my $ua = new LWP::UserAgent; push @{ $ua->requests_redirectable },'POST'; my $request = HTTP::Request->new(POST => 'http://blah.blah'); $request->content_type('application/x-www-form-urlencoded'); $request->content("LOGIN1=$action&Y=$Y&p=$P"); my $resp = $ua->request($request); Any ideas what I'm doing wrong? Ian |
Re: LWP and 302 redirects
On Wed, 4 Oct 2006, Mumia W. (reading news) wrote:
> This is from the HTTP specification at > ftp://ftp.isi.edu/in-notes/rfc2616.txt > > > If the 302 status code is received in response to a request other > > than GET or HEAD, the user agent MUST NOT automatically redirect the > > request unless it can be confirmed by the user, since this might > > change the conditions under which the request was issued. [ I note that this would be more at home on comp.infosystems.www.authoring.cgi (beware the automoderation bot), since there's now rather little Perl-specific about it. But ho hum. ] The behaviour of actual browsers is not necessarily in conformance with RFC2616, unfortunately. I have the impression that some things got a lot better in recent browser versions, as compared with the time that I originally wrote this page http://ppewww.ph.gla.ac.uk/~flavell/www/post-redirect "Redirect in response to POST transaction". But some users still use old browser/versions, and when you're configuring a server for use on the WWW, you need to make some kind of provision (if only to refuse service, but that's not very nice) if the browser does not behave itself. > If 'http://blah.blah' is a script that you wrote, you can return a > 303 (or 307 ?) status. If not, you'll have to look at the returned > headers to figure out where to post the form. My recommendation would be to configure the user-advertised URL as a proxy, which sends the POST transaction to the other URL, behind the scenes, captures the result, and feeds it back (reformatted as necessary) to the user. In that way, the browser has no idea what the actual machinery is, and there's no need to care how well the browser supports 30x redirection of POST request. Disclaimer: due to tiredness I haven't analyzed in detail what the O.P is trying to achieve overall. But the mention of 30x and POST triggered these rather general comments. Errata: A recent email rebuked me for writing as if "idempotent" was synonymous with "not producing side effects". I knew that already, and will be adjusting the wording to try to make that clear. Hope that helps a bit. |
Re: LWP and 302 redirects
IanW wrote:
> Hi > > I'm having trouble with LWP and 302 redirects. I found the > "$ua->requests_redirectable" parameter in the LWP documentation but it still > doesn't work. Here's my code: Define "doesn't work". What is returned for the response or error? > > use LWP::UserAgent; > my $ua = new LWP::UserAgent; > push @{ $ua->requests_redirectable },'POST'; > my $request = HTTP::Request->new(POST => 'http://blah.blah'); > $request->content_type('application/x-www-form-urlencoded'); > $request->content("LOGIN1=$action&Y=$Y&p=$P"); > my $resp = $ua->request($request); > > Any ideas what I'm doing wrong? > > Ian > > |
| All times are GMT. The time now is 06:30 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.