【问题标题】:How to PUT a file using Mojo::Useragent?如何使用 Mojo::Useragent 放置文件?
【发布时间】:2019-07-19 09:16:52
【问题描述】:

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

【问题讨论】:

    标签: perl mojolicious http-put mojo-useragent


    【解决方案1】:

    请参阅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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-14
      • 1970-01-01
      • 1970-01-01
      • 2018-11-30
      • 1970-01-01
      • 1970-01-01
      • 2015-12-09
      • 1970-01-01
      相关资源
      最近更新 更多