Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   LWP and 302 redirects (http://www.velocityreviews.com/forums/t900179-lwp-and-302-redirects.html)

IanW 10-04-2006 08:19 AM

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



Alan J. Flavell 10-04-2006 03:51 PM

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.


J. Gleixner 10-05-2006 05:52 PM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57