How can I send POST and GET data to a Perl CGI scr

2019-01-21 23:33发布

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! :)

8条回答
迷人小祖宗
2楼-- · 2019-01-22 00:14

If you don't want to alter the perl script, you can call it with at least two environment variables set, as others mentioned already. To simulate a GET request:

shell$ QUERY_STRING=limit=20 REQUEST_METHOD=GET ./events_html.pl

That's the console shortcut for www.myserver.org/events_html.pl?limit=20

查看更多
疯言疯语
3楼-- · 2019-01-22 00:15

Yes, it's possible to do this from the command line, bypassing your server. This page explains all: Perl CGI debugging (sitewizard.com) (Especially item 6 on that page). Here I quote the most important part:

To test the script offline using the GET method, simply set the QUERY_STRING environment variable accordingly. If you are using Windows, you might use the following command line in a DOS window prior to running the script in the same window:

set QUERY_STRING=recipient=John@Doe.com&Fullname=M+Name

To test the script offline using the POST method, put the line below into a text file named, say, testinput.txt.

recipient=John@Doe.com&Fullname=M+Name

Then redirect that file as an input to the script. On Unix systems as well as under Windows' MSDOS prompt, you can do it this way:

perl -w scriptname.pl < testinput.txt

Your script will then receive that input as though it was sent it by a form on the website. Check the error messages that perl spouts, if any, to help you track the problem in the script.

查看更多
登录 后发表回答