开发者

Are there any problems handling a POST request as a GET request on the server

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 开发者_如何学Pythonmethod 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?


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;


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜