问题
In an attempt to resolve the issue I posted in this question:
Is it possible to send POST parameters to a CGI script using a system() call?
So far the only successful resolution to the problem is to trick the environment to think the request was a GET. I do this by converting the POST parameters to a query string, saving that string in the default environment variable, then changing the environment variable that tells the server what method this request is using to GET.
$ENV{'QUERY_STRING'} = $long_parameter_string . '&' . $ENV{'QUERY_STRING'};
$ENV{'REQUEST_METHOD'} = 'GET';
system {$perl_exec} $cgi_script;
I'm essentially tricking the CGI module to read from the QUERY_STRING environment variable instead of from STDIN, which it would attempt to read POST requests from.
This method seems to work so far, but I'm worried about unintended repercussions.
My question is, do you see any potential problems with this?
回答1:
You'll hit problems with larger submissions and file-uploads as the size limit for a GET is much smaller than a POST. If you're talking about predictably small amounts of data, you should be alright.
回答2:
POST and GET mean entirely different things, and you shouldn't be "testing" anything that way.
Instead, you should do a real POST to the intended URL by using Perl's LWP.
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
my $req = POST 'http://www.perl.com/cgi-bin/BugGlimpse',
[ param1 => 'arbitrarily long blob', param2 => 'whatever' ];
print $ua->request($req)->as_string;
来源:https://stackoverflow.com/questions/1860716/are-there-any-problems-handling-a-post-request-as-a-get-request-on-the-server