perl - 当表单发布到我的脚本时,如何访问 URL 中传递的参数?

标签 perl post parameters cgi get

我遇到了 mod_rewrite 的问题在向我们的站点 perl 脚本提交表单时。如果有人在具有诸如 http://www.example.com/us/florida/page-title 之类的 url 的页面上执行 GET 请求,我将使用以下正确工作的重写规则重写它:

RewriteRule ^us/(.*)/(.*)$ /cgi-bin/script.pl?action=Display&state=$1&page=$2 [NC,L,QSA]

Now, if that page had a form on it I'd like to do a form post to the same url and have Mod Rewrite use the same rewrite rule to call the same script and invoke the same action. However, what's happening is that the rewrite rule is being triggered, the correct script is being called and all form POST variables are being posted, however, the rewritten parameters (action, state & page in this example) aren't being passed to the Perl script. I'm accessing these variables using the same Perl code for both the GET and POST requests:

use CGI;
$query = new CGI;
$action = $query->param('action');
$state = $query->param('state');
$page = $query->param('page');

我添加了 QSA 标志,因为我认为这可能会解决问题,但事实并非如此。如果我直接对脚本 URL 执行 POST,则一切正常。如果您能帮助我弄清楚为什么这目前不起作用,我将不胜感激。提前致谢!

最佳答案

如果您正在执行 POST 查询,则需要使用 $query->url_param('action')等从查询字符串中获取参数。您不需要 QSA 修改器,也不需要从中受益。

关于perl - 当表单发布到我的脚本时,如何访问 URL 中传递的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1578185/

相关文章:

asp.net - OLEDBException:vb.net 中没有为一个或多个必需参数给出值

perl - 将 Perl 中的 Pi 舍入到小数点后第 100 位?

java - 这是通过 HTTP POST 向 java Web 服务器提交 JSON 的正确方法吗?

php://input 在 POST 请求中为空

java - 在非指定方法中交换变量

parameters - Azure 数据工厂 - 使用包参数执行 SSIS 包

python - 从大文本文件中删除重复项

perl - 如何使用 Expect.pm 将箭头键按下发送到进程

c++ - 如何在 Perl 脚本中调用 C++ 程序?

python - 在 Python 中创建 POST 请求