Downloading with wget using referer + cookie

3

1

I'm trying to download a file from a website that requires login. This command retrieves the cookie.txt and the downloaded html shows I'm logged in (ok):

(I broke the command in lines for readability)

wget 
--user-agent="Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) 
Gecko/20100101 Firefox/45.0" 
--keep-session-cookies
--save-cookies cookies.txt
--post-data "login_username=MyUserName&login_password=*******" 
--header="Host: somewebsite.com"
--header="Referer: http://somewebsite.com/files/download.php?i=2157716" 
http://somewebsite.com/login.php

Here I get cookies.txt. (all ok). And after that: (trying to download)

wget 
--user-agent="Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) 
Gecko/20100101 Firefox/45.0" 
--load-cookies cookies.txt
--header="Host: somewebsite.com"
--header="Referer: http://somewebsite.com/files/download.php?i=2157716" 
--header="Connection: keep-alive" --header="Accept-Language: en-US,en;q=0.5"
--header="Accept-Encoding: gzip, deflate"
http://somewebsite.com/files/dl.php?t=2157716

But instead of downloading the file it returns an HTML saying that the file can only be downloaded from the website.

Here is the POST data from Firefox right before the download starts:

post data from actual Firefox download

What is missing?

Azevedo

Posted 2016-04-05T00:14:58.797

Reputation: 511

Could be that the url you think is the download isn't. For example, wget doesn't handle javascript redirects. – Ouroborus – 2016-04-05T01:09:08.990

Answers

1

Solved. The HTML has a hidden form that sends the request via POST. I just had to add --post-data "login_username=****&login_password=****". The server only starts the download if it is POST request.

Azevedo

Posted 2016-04-05T00:14:58.797

Reputation: 511