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

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

+6
uri perl cgi
source share
3 answers

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

For POST requests , param() will return parameters from postdata, but any parameters specified in the request line in the URL itself are still accessible from the url_param() method. (This can be useful when the POST request is greater than $CGI::POST_MAX ; in this case, CGI just discards the postdata data, but you can order the query string parameters that determine which request it should have provided, a good error message. )

For ISINDEX style queries, the requested keywords are available using the keywords() method, as well as via param() in the optional keyword.

Update: if you meant something other than parameters by the URL parameter, the url() method provides all or parts of the requested URL; see GETTING A SCRIPT URL .

+12
source share

It is recommended that you use a URL parser, such as ysth, but if you really want the original input, it is available through the following:

for GET:

 $contents = $ENV{'QUERY_STRING'}; 

for POST:

 $contents = <STDIN>; 
+4
source share

Try the code this way:

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

All Articles