0
有一個網頁,其包括形式內部的按鈕。單擊該按鈕可以使一個POST請求和CSV文件被下載。POST請求來下載文件
我試圖使用自動化LWP :: UserAgent的的CSV下載過程。
我從Chrome開發人員工具注意到Content-Type
爲multipart/form-data; boundary=---WebKitFormBoundary....
任何想法,我怎麼能發送確切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