Mumia W. wrote:
Mumia W. wrote:
On 08/25/2007 04:32 PM, Gunnar Hjalmarsson wrote:
Jeff Pang wrote:
2007/8/25, Praveena Vittal <[EMAIL PROTECTED]>:
I want to redirect to a different url with the parameters in the
post
method.
Well,see 'perldoc CGI' and specially check for,
param,
redirect.
How do you combine a POST request and a 'Location:' header (which is
what CGI::redirect prints AFAIK)?
I think this is called a Status 307 Temporary Redirect. See RFC 2616
ยง 10.3.8.
I do wish the Praveena had been more specific about what he or she is
trying to do, but, if status 307 is appropriate, this is how it can be
done with CGI.pm:
use strict;
use warnings;
use CGI;
# You set the $location.
print CGI::header(
-status => '307 Temporary Redirect',
-location => $location,
);
No, that prints a content-type header as well, and doesn't redirect.
Suppose you meant:
print CGI::redirect($location, -status=>307);
or, more straightforward
print "Status: 307\nLocation: $location\n\n";
Anyway, thanks for mentioning this 'magic' status code, Mumia. I learned
something new today. :)
This is my understanding of how it works:
When you POST a form, and the server responds with status code 307 plus
a location header, the browser displays a confirm box giving you the
option to resend the request to the target location, or cancel the request.
If the client isn't a web browser, but e.g. a Perl script that POSTs
some data, you can bypass the confirmation step:
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
push @{ $ua->requests_redirectable }, 'POST';
$ua->post( $url, [ var1 => 'foo', var2 => 'bar' ] );
In that case, also the status code "301 Moved Permanently" lets the
parameters be passed on to the target location.
Btw, is this technique properly documented anywhere, or would it be a
suitable addition to perlfaq9?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/