如何从命令行测试Perl CGI脚本的文件上传?

问题描述 投票:1回答:1

我有一个调用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?)和其他问题,但找不到任何从命令行传递文件进行上传的信息。在此先感谢您的帮助。

perl file command-line upload cgi
1个回答
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
    '
)
© www.soinside.com 2019 - 2024. All rights reserved.