Pra*_*eep 5 perl http-put mojolicious 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;
Run Code Online (Sandbox Code Playgroud)
请参阅build_tx
Mojo::UserAgent和注释的示例
# PUT request with content streamed from file\n
Run Code Online (Sandbox Code Playgroud)\n\n在tx
Mojo::UserAgent::Transactor 中。
my $ua = Mojo::UserAgent->new;\nmy $put = $ua->build_tx(PUT => \'\xe2\x80\xa6\' => {\'X-Test\' => \'123G\'});\n$put->req->content->asset(Mojo::Asset::File->new(path => $file));\nmy $tx = $ua->start($put);\n
Run Code Online (Sandbox Code Playgroud)\n