我有一个调用my $file_handle = $cgi->upload('uploaded_file')
的Perl脚本。在部署到Web服务器之前,是否可以通过命令行测试此脚本?我看了(How can I send POST and GET data to a Perl CGI script via the command line?)和其他问题,但找不到用于从命令行传递要上传的文件的任何信息。预先感谢您的帮助。
答案 0 :(得分:3)
文件上传只是另一个POST请求!参见DEBUGGING in CGI.pm。程序为index.pl
,要上传的文件为somefile.bin
,表单字段名称为uploaded_file
:
REQUEST_METHOD=POST \
CONTENT_TYPE='multipart/form-data; boundary=xYzZY' \
perl index.pl < <(
perl -MHTTP::Request::Common=POST -e'
print POST(
undef,
Content_Type => "form-data",
Content => [ uploaded_file => [ "somefile.bin" ]]
)->content
'
)