【发布时间】:2018-06-05 16:57:05
【问题描述】:
我正在尝试 POST file 到 webapp 端点。问题是在同一个请求中,我需要包含数组作为参数之一的值。
my $ua = LWP::UserAgent->new();
my $response = $ua->post(
$baseurl_local . 'create',
Content_Type => 'form-data',
Content => [
file => [$file],
targetLang => 'french',
]);
工作得很好。
但是当我尝试时
my $ua = LWP::UserAgent->new();
my $response = $ua->post(
$baseurl_local . 'create',
Content_Type => 'form-data',
Content => [
file => [$file],
targetLang => ['french','spanish],
]);
我明白了
无法打开文件法语:C:/Strawberry/perl/site/lib/HTTP/Request/Common.pm 第 154 行没有这样的文件或目录。 HTTP::Request::Common::form_data(ARRAY(0x6800698), undef, HTTP::Request=HASH(0x6803a70)) 在 C:/Strawberry/perl/site/lib/HTTP/Request/Common.pm 第 67 行调用
似乎 Perl 认为带有语言的数组 ref 是一个文件。
我做错了什么?
根据马特的回答扩展解决方案:正如我最初忘记提及的那样,语言列表来自用户输入,所以我最终做了类似的事情:
my @languages = (targetLang => 'french', targetLang => 'spanish');
my $ua = LWP::UserAgent->new();
my $response = $ua->post(
$baseurl_local . 'create',
Content_Type => 'form-data',
Content => [
file => [$file],
@languages,
]);
【问题讨论】: