小编Dee*_*ula的帖子

Perl - HTTP :: Request :: Common - POST文件和数组

我正在尝试将文件POST到webapp端点.问题是在同一个请求中我需要将数组包含为其中一个参数的值.

my $ua = LWP::UserAgent->new();
my $response = $ua->post(
    $baseurl_local . 'create',
    Content_Type => 'form-data',
    Content      => [
    file =>  [$file],
    targetLang => 'french',
]);
Run Code Online (Sandbox Code Playgroud)

工作得很好.

但是,当我尝试

my $ua = LWP::UserAgent->new();
my $response = $ua->post(
    $baseurl_local . 'create',
    Content_Type => 'form-data',
    Content      => [
    file =>  [$file],
    targetLang => ['french','spanish],
]);
Run Code Online (Sandbox Code Playgroud)

我明白了

无法打开文件法语: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认为使用语言的数组引用是一个文件.

我究竟做错了什么?


根据Matt的答案扩展分辨率:我最初忘了提及,语言列表来自用户输入,所以我最终做了类似的事情:

my @languages = (targetLang => 'french', targetLang => 'spanish');
my $ua = LWP::UserAgent->new(); …
Run Code Online (Sandbox Code Playgroud)

perl post

3
推荐指数
1
解决办法
534
查看次数

标签 统计

perl ×1

post ×1