Parris Parris - 6 months ago 31
Perl Question

How can I send POST and GET data to a Perl CGI script via the command line?

I am trying to send a get or a post through a command-line argument. That is test the script in the command line before I test through a browser (the server has issues). I tried searching online, and I suppose I was probably using incorrect terminology because I got nothing. I know this is possible because I saw someone do it. I just don't remember how it was done.

Thanks! :)

Answer Source

Are you using the standard CGI module?

For example, with the following program (notice -debug in the arguments to use CGI)

#! /usr/bin/perl

use warnings;
use strict;

use CGI qw/ :standard -debug /;

print "Content-type: text/plain\n\n",
      map { $_ . " => " . param($_) . "\n" }

you feed it parameters on the command line:

$ ./prog.cgi foo=bar baz=quux
Content-type: text/plain

foo => bar
baz => quux

You can also do so via the standard input:

$ ./prog.cgi
(offline mode: enter name=value pairs on standard input; press ^D or ^Z when done)
Content-type: text/plain

foo => bar
baz => quux
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download