在服务器上将 POST 请求作为 GET 请求处理时是否存在任何问题

发布于 2024-08-13 23:57:19 字数 631 浏览 6 评论 0原文

为了解决我在此问题中发布的问题:

是否可以使用 system() 调用将 POST 参数发送到 CGI 脚本?

到目前为止,该问题唯一成功的解决方案是欺骗环境认为请求是 GET。为此,我将 POST 参数转换为查询字符串,将该字符串保存在默认环境变量中,然后更改环境变量,告诉服务器此请求使用什么方法进行 GET。

$ENV{'QUERY_STRING'} = $long_parameter_string . '&' . $ENV{'QUERY_STRING'};
$ENV{'REQUEST_METHOD'} = 'GET';

system {$perl_exec} $cgi_script;

我本质上是在欺骗 CGI 模块从 QUERY_STRING 环境变量而不是 STDIN 中读取数据,它会尝试从中读取 POST 请求。

到目前为止,这种方法似乎有效,但我担心会产生意想不到的影响。

我的问题是,您认为这有任何潜在的问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜点 2024-08-20 23:57:19

POST 和 GET 意味着完全不同的东西,并且您不应该以这种方式“测试”任何东西。

相反,您应该使用 Perl 的 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;

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;
执妄 2024-08-20 23:57:19

您会遇到较大提交和文件上传的问题,因为 GET 的大小限制比 POST 小得多。如果您谈论的是可预见的少量数据,那么应该没问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文