CGI命令行Args消失

编程入门 行业动态 更新时间:2024-10-28 08:31:27
本文介绍了CGI命令行Args消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个cgi脚本,该脚本调用了另一个cgi脚本.

I have a cgi script that calls another cgi script.

main_script.cgi脚本如下:

main_script.cgi script looks like this:

print qx/child_script.cgi arg1=foo arg2=bar/;

child_script.cgi看起来像这样:

child_script.cgi looks something like this:

use CGI; use Data::Dumper; my $query = CGI->new; warn Dumper($query);

如果我在外壳中执行./main_script.cgi,则会得到:

If I do ./main_script.cgi in the shell, I get:

$VAR1 = bless( { '.parameters' => [ 'arg1', 'arg2' ], 'use_tempfile' => 1, '.charset' => 'ISO-8859-1', '.fieldnames' => {}, 'param' => { 'arg1' => [ 'foo' ], 'arg2' => [ 'bar' ] }, 'escape' => 1 }, 'CGI' );

但是,如果我在浏览器中访问myhost/main_script.cgi,则输出为:

But if I visit myhost/main_script.cgi in the browser, the output is:

$VAR1 = bless( { '.parameters' => [], 'use_tempfile' => 1, '.charset' => 'ISO-8859-1', '.fieldnames' => {}, 'param' => {}, 'escape' => 1 }, 'CGI' );

推荐答案

您的辅助脚本正在从您的第一个脚本继承%ENV .如果 CGI 看到 REQUEST_METHOD ,它将忽略命令行参数,而是从 QUERY_STRING 等中加载内容.

Your secondary script is inheriting %ENV from your first script. If CGI sees a REQUEST_METHOD it ignores the commandline parameters and instead loads things from the QUERY_STRING, etc.

要解决此问题,您必须首先本地化%ENV 并删除 REQUEST_METHOD .

To fix this, you must first localize the %ENV and delete the REQUEST_METHOD.

以下内容证明了这一点:

The following demonstrates this:

part1.pl

#!perl use strict; use warnings; use CGI; use Data::Dump; my $q = CGI->new; print "Content-type: text/plain; charset=iso-8859-1\n\n"; dd $q; # Localize the REQUEST_METHOD so that the secondary process doesn't see it. my $text = do { local $ENV{REQUEST_METHOD}; qx(perl part2.pl arg1=val1 arg2=val2); }; print $text;

part2.pl

#!perl use strict; use warnings; use CGI; use Data::Dump; my $q = CGI->new; print "Content-type: text/plain; charset=iso-8859-1\n\n"; dd $q;

访问 localhost/cgi-bin/part1.pl?a = 1& b = 2 会显示以下内容:

bless({ ".charset" => "ISO-8859-1", ".fieldnames" => {}, ".parameters" => ["a", "b"], "escape" => 1, "param" => { a => [1], b => [2] }, "use_tempfile" => 1, }, "CGI") Content-type: text/plain; charset=iso-8859-1 bless({ ".charset" => "ISO-8859-1", ".fieldnames" => {}, ".parameters" => ["arg1", "arg2"], "escape" => 1, "param" => { arg1 => ["val1"], arg2 => ["val2"] }, "use_tempfile" => 1, }, "CGI")

更多推荐

CGI命令行Args消失

本文发布于:2023-10-25 18:42:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1527776.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令行   CGI   Args

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!