我尝试使用PUT方法通过Mojo::UserAgent上传文件,该文件可能很大,而不是将文件内容作为标量传递,还有其他方法吗?
这是我尝试过的:
use strict;
use warnings;
use Mojo::UserAgent;
use Mojo::Asset::File;
my $ua = Mojo::UserAgent->new;
my $file = $ARGV[0];
die("File not found") unless(-f $file);
my $a_file = Mojo::Asset::File->new(path => $file);
my $tx = $ua->put('https://postman-echo.com/put' => {'X-Test' => '123G'} => $a_file);
print $tx->success;
print "\n\n";
print $tx->result->body;
print "\n\n";
print $tx->req->text;
最佳答案
参见 build_tx
in Mojo::UserAgent并注释示例
# PUT request with content streamed from file
在
tx
in Mojo::UserAgent::Transactor。my $ua = Mojo::UserAgent->new;
my $put = $ua->build_tx(PUT => '…' => {'X-Test' => '123G'});
$put->req->content->asset(Mojo::Asset::File->new(path => $file));
my $tx = $ua->start($put);
关于perl - 如何使用Mojo::Useragent放置文件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57109294/