How can I read the URL parameter in a Perl CGI program?
如何读取Perl CGI程序中的URL参数?
3 个解决方案
#1
For GET requests, CGI parses the specified parameters and makes them available via the param()
method.
对于GET请求,CGI解析指定的参数并通过param()方法使它们可用。
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.)
对于POST请求,param()将从postdata返回参数,但是通过URL本身中的查询字符串指定的任何参数仍然可以从url_param()方法获得。 (当POST请求大于$ CGI :: POST_MAX时,这可能会有所帮助;在这种情况下,CGI只会丢弃postdata,但您可以安排查询字符串参数,以确定提供良好的请求的请求类型错误信息。)
For ISINDEX style requests, the keywords requested are available via the keywords()
method, as well as via param()
in a faux "keywords" parameter.
对于ISINDEX样式请求,请求的关键字可通过keywords()方法获得,也可通过仿“关键字”参数中的param()获得。
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.
更新:如果您通过“URL参数”表示除参数之外的其他内容,则url()方法提供所请求的URL的全部或部分;请参阅获取SCRIPT的URL。
#2
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:
建议你使用ysth提到的URL解析器,但如果你真的想要原始输入,可以通过以下方式获得:
for GET:
$contents = $ENV{'QUERY_STRING'};
for POST:
$contents = <STDIN>;
#3
Try thus code:
试试这样的代码:
my @names = $query->param;
foreach $name ( @names ) {
if ( $name =~ /\_/ ) {
next;
} else {
print "<p> ".$name."\t=\t".$query->param($name) . "</p>\n";
}
}
#1
For GET requests, CGI parses the specified parameters and makes them available via the param()
method.
对于GET请求,CGI解析指定的参数并通过param()方法使它们可用。
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.)
对于POST请求,param()将从postdata返回参数,但是通过URL本身中的查询字符串指定的任何参数仍然可以从url_param()方法获得。 (当POST请求大于$ CGI :: POST_MAX时,这可能会有所帮助;在这种情况下,CGI只会丢弃postdata,但您可以安排查询字符串参数,以确定提供良好的请求的请求类型错误信息。)
For ISINDEX style requests, the keywords requested are available via the keywords()
method, as well as via param()
in a faux "keywords" parameter.
对于ISINDEX样式请求,请求的关键字可通过keywords()方法获得,也可通过仿“关键字”参数中的param()获得。
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.
更新:如果您通过“URL参数”表示除参数之外的其他内容,则url()方法提供所请求的URL的全部或部分;请参阅获取SCRIPT的URL。
#2
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:
建议你使用ysth提到的URL解析器,但如果你真的想要原始输入,可以通过以下方式获得:
for GET:
$contents = $ENV{'QUERY_STRING'};
for POST:
$contents = <STDIN>;
#3
Try thus code:
试试这样的代码:
my @names = $query->param;
foreach $name ( @names ) {
if ( $name =~ /\_/ ) {
next;
} else {
print "<p> ".$name."\t=\t".$query->param($name) . "</p>\n";
}
}