如何读取 Perl CGI 程序中的 URL 参数?

发布于 2024-07-24 16:19:49 字数 33 浏览 3 评论 0原文

如何读取 Perl CGI 程序中的 URL 参数?

How can I read the URL parameter in a Perl CGI program?

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

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

发布评论

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

评论(3

找回味觉 2024-07-31 16:19:49

对于 GET 请求CGI 解析指定的参数并使它们可用通过 param() 方法。

对于 POST 请求param() 将从 postdata 返回参数,但通过 URL 本身中的查询字符串指定的任何参数仍然可以从 url_param 获取() 方法。 (当 POST 请求大于 $CGI::POST_MAX 时,这会很有帮助;在这种情况下,CGI 只是丢弃 postdata,但您可以安排查询字符串参数来标识哪种类型请求它是为了提供一个好的错误消息。)

对于 ISINDEX 样式请求,请求的关键字可通过 keywords() 方法以及通过 param 获得() 在一个虚假的“关键字”参数中。

更新:如果您指的是“URL 参数”中的参数以外的其他内容,url() 方法会提供所请求的 URL 的全部或部分; 请参阅获取脚本的 URL

For GET requests, CGI parses the specified parameters and makes them available via the param() method.

For POST requests, param() will return the parameters from the postdata, but any parameters specified via a query string in the URL itself are still available from the url_param() method. (This is can be helpful when a POST request is larger than $CGI::POST_MAX; in that case, CGI just discards the postdata, but you can arrange to have query string parameters that identify what kind of request it was to provide a good error message.)

For ISINDEX style requests, the keywords requested are available via the keywords() method, as well as via param() in a faux "keywords" parameter.

Update: in case you meant something other than the parameters by "URL Parameter", the url() method provides all or parts of the requested URL; see OBTAINING THE SCRIPT'S URL.

只为守护你 2024-07-31 16:19:49

建议您使用 ysth 提到的 URL 解析器,但如果您确实想要原始输入,可以通过以下方式获得:

对于 GET:

$contents = $ENV{'QUERY_STRING'};

对于 POST:

$contents = <STDIN>;

It's recommended that you use a URL parser such as mentioned by ysth, but if you REALLY want the raw input, it's available through the following:

for GET:

$contents = $ENV{'QUERY_STRING'};

for POST:

$contents = <STDIN>;
时常饿 2024-07-31 16:19:49

尝试这样的代码:

my @names = $query->param;
foreach $name ( @names ) {
    if (  $name =~ /\_/ ) { 
        next;
    } else {
        print "<p> ".$name."\t=\t".$query->param($name) . "</p>\n";
    }
}

Try thus code:

my @names = $query->param;
foreach $name ( @names ) {
    if (  $name =~ /\_/ ) { 
        next;
    } else {
        print "<p> ".$name."\t=\t".$query->param($name) . "</p>\n";
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文