Perl 使用多部分/表单数据内容类型发布下载文件的请求

Perl 使用多部分/表单数据内容类型发布下载文件的请求,perl,lwp-useragent,Perl,Lwp Useragent,表单中有一个包含按钮的网页。点击该按钮发出POST请求,并下载CSV文件 我正在尝试使用LWP::UserAgent自动化CSV下载过程 我从Chrome开发者工具中注意到,内容类型是多部分/表单数据;边界=---WebKitFormBoundary… 知道我如何发送确切的请求有效负载哪些开发人员工具正在显示吗 我通常对x-www-form-urlencoded内容类型执行以下操作。但我不知道如何提交多部分表单数据 my $ua = LWP::UserAgent->new; $ua->

表单中有一个包含按钮的网页。点击该按钮发出POST请求,并下载CSV文件

我正在尝试使用LWP::UserAgent自动化CSV下载过程

我从Chrome开发者工具中注意到,
内容类型是
多部分/表单数据;边界=---WebKitFormBoundary…

知道我如何发送确切的
请求有效负载
哪些开发人员工具正在显示吗

我通常对
x-www-form-urlencoded
内容类型执行以下操作。但我不知道如何提交多部分表单数据

my $ua = LWP::UserAgent->new;
$ua->cookie_jar({ file => "cookie.txt", autosave => 1});


my $request = HTTP::Request->new('POST', $url);

#copy the form_data from chrome developer tools
my $form_data = 'key=val&key2=val2';

#the form_data is too big (and is in parts) in case of multipart content type

$request->content($form_data);
$request->header('Content-Type' => "application/x-www-form-urlencoded");
#I'll have to use `multipart/form-data; boundary=---WebKitFormBoundary....`

#add some other headers like 'Origin', 'Host' and 'Referer' in similar manner
#...
#...

push @{ $ua->requests_redirectable }, 'POST';

my $response = $ua->request($request);

#Get the file

查看中
POST
上的条目

您可以通过传递
Content\u Type=>“表单数据”的伪头值来生成
多部分/表单数据
请求(而不是
application/x-www-form-urlencoded

看起来是这样的

my $response = $ua->post(
    $url,
    Content_Type => 'form-data',
    {
        ...;  # Hash of form key/value pairs
    }
);

查看中
POST
上的条目

您可以通过传递
Content\u Type=>“表单数据”的伪头值来生成
多部分/表单数据
请求(而不是
application/x-www-form-urlencoded

看起来是这样的

my $response = $ua->post(
    $url,
    Content_Type => 'form-data',
    {
        ...;  # Hash of form key/value pairs
    }
);