Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Passing URL parameters to a CGI script from the shell

by Bilbo (Pilgrim)
on Apr 01, 2003 at 19:05 UTC ( [id://247314]=perlquestion: print w/replies, xml ) Need Help??

Bilbo has asked for the wisdom of the Perl Monks concerning the following question:

I feel that I must be missing something obvious here. I am trying to test a CGI script (using the CGI module) by running it from the shell. I can pass parameters to be recovered using the param method by specifying them on the command line, as shown in the CGI documentation. How do I pass parameters to be retrieved using the url-param method? In other words, how do I make my script think that it has been invoked by CGI with a URL like http://myhost.org.uk/forum.cgi?mode=1?

Replies are listed 'Best First'.
Re: Passing URL parameters to a CGI script from the shell
by cbro (Pilgrim) on Apr 01, 2003 at 19:27 UTC
    Try setting the QUERY_STRING environment variable. Just load it up with all of the values, and run your CGI script via command line.
    For example:
    $ENV{QUERY_STRING} = "iid=26&rid=2&ptype=t";

    ...where iid, rid, and ptype are all normally passed via URL as you outlined in your question.

      Thanks. That did the trick.

Re: Passing URL parameters to a CGI script from the shell
by jasonk (Parson) on Apr 01, 2003 at 19:36 UTC

    url_param is only useful when POSTing to a CGI, to differentiate between the posted values and the url values. When you use the command line debugging functionality, CGI.pm simply turns the options you give it into a query string, and simulates a GET (technically it isn't a GET, because from the command line you get no $REQUEST_METHOD, but it works similarly), the code doesn't provide this functionality from the command line.


    We're not surrounded, we're in a target-rich environment!
Re: Passing URL parameters to a CGI script from the shell
by The Mad Hatter (Priest) on Apr 01, 2003 at 19:59 UTC
    What jasonk said was good. If you don't really need to use url_param (I don't know if you do), you can use the param method (which will fetch data from POST or GET) and easily emulate the script being passed data by specifying name=value pairs as arguments. For example: ./myscript.cgi mode=1 foo=bar.

    Update Just wanted to note that cbro was right about using QUERY_STRING.

Re: Passing URL parameters to a CGI script from the shell
by Anonymous Monk on Jan 16, 2015 at 07:24 UTC
    www.google.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://247314]
Approved by Thelonius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-03-29 14:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found