[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-WebCGI] Re: Location:



My thanks to Peter R. Wiley and Christian Huldt for straightening me out on
the Location: directive in HTTP.

I thought it was telling the client:
 "do what you were going to do here, but do it at the following URL"

...when in fact it appears to be telling the client:
 "the information you require is at the following URL"

This means there is no way to redirect a POST; the best you can do is
convert it to a GET.

This is unfortunate, as GET lacks some capabilities of POST.

However, given that, I went ahead and started modifying my script (as Peter
and Christian suggested) to read the POST arguments and add them to the
Location: URL for a GET and ran into a problem.  (Code for a test cgi is
appended.)

I prototyped this using MacPERL (thus I'm on topic :-), using CGI.pm, and
it worked like a charm.

I moved it to Linux, and it stopped working; the redirect method in CGI.pm
truncates the URL at the first quote character.  (I am enclosing values in
quotes as I don't know in advance what they will be; certain values require
quotes.)

The CGI.pm files are identical, except for the $CGI::revision line.

This is of only theoretical interest, as I can solve the immediate problem
by just printing the Location: line manually.  It is of general and MacPERL
interest (IMHO) because of what it implies for portability.

Any thoughts?

THANKS!

-David-

#!/usr/bin/perl
#
# test.cgi
#
# Returns a page with proposed Location: output

use CGI;

$query = new CGI;

$s  = "http://glutamine.biomedcomp.com/4d.acgi?";
$s .= $query->script_name(); # need to fix; remove /cgi-bin/
$s .= '$'; # how to pass arguments to Netlink 4D

# Convert POST arguments to GET
foreach $key ($query->param) {
    @values = $query->param($key);
    foreach $value (@values) {
        $s .= "$key=\"$value\"&";
    }
}
chop($s); # remove the final '&'

print $query->header;
print $query->start_html("Steffen's Form Tester");
print "<H1>Steffen's Form Tester</H1>\n";

print "<p>$s<\p>\n"; # this works fine on Linux and Mac

# The final program will print this as a header.
# I am printing it as output now for debugging.
print "<pre>\n";
print $query->redirect(-uri=>$s, -nph=>0);
# The previous line works fine on a Mac, but truncates after
# the first quote [\"] character on Linux
print "</pre>\n";

print $query->end_html;


David Steffen, Ph.D.
President, Biomedical Computing, Inc. <http://www.biomedcomp.com/>
Phone: (713) 610-9770 FAX: (713) 610-9769 E-mail: steffen@biomedcomp.com



==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org