perl - 如何使用 Mojo::Useragent 放置文件?

标签 perl mojolicious http-put mojo-useragent

我正在尝试使用 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/

相关文章:

java - Hibernate 幂等更新

perl - 重新运行循环迭代

javascript - 在 Mojolicious 中解码使用 JSON.stringify 编码的 JSON 字符串

MySQL 注释导致 Perl DBI 的绑定(bind)参数计数困惑

perl - 打包和部署 mojolicious 应用程序的最佳方式

perl - 从 DELETE 路由重定向后无法测试呈现的输出 - Mojolicious

php - HTTP协议(protocol)的PUT和DELETE及其在PHP中的使用

Java HttpsURLConnection SSLHandshakeException

perl - Catalyst:将查询参数传递给 "forward"调用

perl - 检查一个数字是否位于两个值之间