LWP and 302 redirects


I

IanW

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
 
Ad

Advertisements

A

Alan J. Flavell

This is from the HTTP specification at
ftp://ftp.isi.edu/in-notes/rfc2616.txt

[ 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.
 
Ad

Advertisements

J

J. Gleixner

IanW said:
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top