如何通过命令行将 POST 和 GET 数据发送到 Perl CGI 脚本? [英] How can I send POST and GET data to a Perl CGI script via the command line?
问题描述
我正在尝试通过命令行参数发送 get 或 post.那是在我通过浏览器测试之前在命令行中测试脚本(服务器有问题).我尝试在线搜索,我想我可能使用了不正确的术语,因为我一无所获.我知道这是可能的,因为我看到有人这样做了.我只是不记得它是如何完成的.
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.
谢谢!:)
推荐答案
您使用的是标准 CGI 模块吗?
Are you using the standard CGI module?
例如,使用下面的程序(注意-debug
在参数中use CGI
)
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
",
map { $_ . " => " . param($_) . "
" }
param;
您在命令行上为其提供参数:
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)
foo=bar
baz=quux
^D
Content-type: text/plain
foo => bar
baz => quux
这篇关于如何通过命令行将 POST 和 GET 数据发送到 Perl CGI 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!