フォームの中にボタンを含むウェブページがあります。そのボタンをクリックすると、POSTリクエストが生成され、CSVファイルがダウンロードされます。ファイルをダウンロードするためのマルチパート/フォームデータコンテンツタイプのPOSTリクエスト
私はLWP :: UserAgentを使用してCSVダウンロードプロセスを自動化しようとしています。
私はContent-Type
がmultipart/form-data; boundary=---WebKitFormBoundary....
でChromeデベロッパーツールから、私は開発ツールが表示されている正確なRequest Payload
を送ることができますどのように任意のアイデアに気づきましたか?
コンテンツタイプは通常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