如何使用 Perl POST 本地文件?

How to POST a local file using Perl?

我有一个服务器 运行 一个 Perl 网络服务。此 Web 服务生成一个 ~75mb .exe 文件。

我想发出 POST 请求,将此文件数据发送到另一个网络服务器。

现在我正在使用 LWP::UserAgent 像这样:

use LWP::UserAgent;

my $ua = LWP::UserAgent->new;

# URL to post to
my $url = "http://my.website.here.com/upload";

# Location of local file
my $file_path = "/path/to/file.exe";

# Make the POST request
my $req = $ua->post(
    $url,
    [ Content_Type => 'form-data', 'file' => [$file_path] ]
);

但是,目前只发送文件名。我明白为什么会这样,但我在这里错过了什么?

非常感谢!

->get->post的参数请参考HTTP::Request::Common

my $req = $ua->post($url,
    [ Content_Type => 'form-data', 'file' => [$file_path] ]
);

应该是

my $req = $ua->post($url,
    Content_Type => 'form-data',
    Content => [
        file => [$file_path],
    ],
);