Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > LWP and 302 redirects

Reply
Thread Tools

LWP and 302 redirects

 
 
IanW
Guest
Posts: n/a
 
      10-04-2006
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


 
Reply With Quote
 
 
 
 
Alan J. Flavell
Guest
Posts: n/a
 
      10-04-2006
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.

 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      10-05-2006
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
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making urllib2's POST 302 handle same as Perl LWP's behaviour Karra Python 2 12-29-2010 02:03 PM
case study: want to print redirects when LWP::UserAgent makes arequest Bennett Haselton Perl Misc 2 03-23-2010 06:18 PM
LWP gives 302 Found after update? John Bokma Perl Misc 5 08-16-2005 07:35 PM
CGIHTTPServer always return 200, no redirects (302) possible Thomas Guettler Python 1 10-26-2004 10:04 PM
LWP::Parallel::UserAgent does not follow redirects Alex Perl Misc 0 12-02-2003 05:44 PM



Advertisments