gpt4 book ai didi

perl - 如何调试用于从客户端上传文件的服务器端脚本(在此示例中为 curl)?

转载 作者:行者123 更新时间:2023-12-04 11:49:13 26 4
gpt4 key购买 nike

我正在尝试从 CLI 编写 Perl Mojolicious 请求。我想将文件作为参数传递给此请求。
以下是我迄今为止尝试过的事情,但无济于事。

下面的例子对我来说很好用。

curl (working):          curl -X POST "http://localhost:3000/uploadtest.pl/status?Token=6d949625-2f07-1e7a-d57a-de0fa949035d"
Mojolicious (working): perl ./uploadtest.pl get -v -M POST /status?"Token=3780e99a-fc2c-54e5-2c31-417f945c1792"

下面是我被卡住的例子,因为下面的 perl 脚本将文件作为输入 [文件上传]:
curl (working):          curl -X POST -F Input_File=@d:/xml/test.xml "http://localhost:3000/uploadtest.pl/upload?Input_Type=XML
Mojolicious (not working): perl ./uploadtest.pl get -v -M POST /upload?"Input_Type=XML&Input_File=d:/xml/test.xml"

如果有人帮助我解决这个问题,那将是非常有帮助的。
#uploadtest.pl

use Mojolicious::Lite;

# Upload form in DATA section
get '/' => 'form';


# Check status
post '/status' => sub {
my $self = shift;
my $Token = $self->param('Token');
$self->render(text => "In process: $Token");
};

# Multipart upload handler
post '/upload' => sub {
my $self = shift;

# Process uploaded file
my $Input_File = $self->param('Input_File');
my $Input_Type = $self->param('Input_Type');
my $size = $Input_File->size;
my $name = $Input_File->filename;
my $upload = $self->req->upload('Input_File');
$upload->move_to("d:/xml/$name"); #move location
$self->render(text => "Thanks for uploading $size byte file $name.");
};

app->start;
__DATA__

@@ form.html.ep
<!DOCTYPE html>
<html>
<head><title>File Upload</title></head>
<body>
<form name="FileUpload" action="http://localhost:3000/uploadtest.pl/upload" enctype="multipart/form-data" method="post">
Input Type:</td><td><input type="text" name="Input_Type" />
Please specify a file:</td><td><input type="file" name="Input_File" size="40"></td></tr>
<input type="submit" value="Submit"/>
</form>
<br><br><br><hr><br><br><br>
<form name="Status" action="http://localhost:3000/uploadtest.pl/status" method="post">
Token ID: <input type="text" name="Token" />
<input type="submit" value="Check Status"/>
</form>
</body>
</html>

最佳答案

恐怕 Mojolicious get 命令不支持从文件生成请求。

perl -Mojo -E 'p("http://localhost:3000" => form => {Input_Type => "XML", Input_File => {file => "d:/xml/test.xml"}})'

您必须使用 ojo单线。

关于perl - 如何调试用于从客户端上传文件的服务器端脚本(在此示例中为 curl)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37611829/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com