Sign in to follow this  
Followers 0
Fasix

How download a file after HTTP POST request

5 posts in this topic

i'm triyng to directly download this file: http://www.computerbase.de/downloads/systemtools/all-in-one-runtimes/

but how?

seems that need a post request that generate URL to download

this is what i've analyzed (with my poor knowledge of http):

http://www.computerbase.de/downloads/systemtools/all-in-one-runtimes/

POST /downloads/systemtools/all-in-one-runtimes/ HTTP/1.1
Host: www.computerbase.de
User-Agent: Mozilla/5.0 (Windows NT 6.3; rv:41.0) Gecko/20100101 Firefox/41.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://www.computerbase.de/downloads/systemtools/all-in-one-runtimes/
Cookie: bbsessionhash=929c12553b82b7e152b78d4fc8b5947e; _ga=GA1.2.1412997295.1444464576; _gat=1; axd=100027621009370024; POPUPCHECK=1444550976759; cookie-consent=1
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 69
token=22fe7062b14ec56ac2ca83cefce59aa51444464589&urlid=82968&direct=1 ;<-- I think this is the string to POST
HTTP/1.1 303 See Other ;<-- Is this the RESPONSE?
Server: nginx
Date: Sat, 10 Oct 2015 08:10:43 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: http://ftp.computerbase.de/dl-758/dr9Vj4h9_HYzQ6dbwDwBDA/1444468243/aio-runtimes_v2.3.0.exe ;<-- FINAL URL
----------------------------------------------------------
http://ftp.computerbase.de/dl-758/dr9Vj4h9_HYzQ6dbwDwBDA/1444468243/aio-runtimes_v2.3.0.exe

GET /dl-758/dr9Vj4h9_HYzQ6dbwDwBDA/1444468243/aio-runtimes_v2.3.0.exe HTTP/1.1
Host: ftp.computerbase.de
User-Agent: Mozilla/5.0 (Windows NT 6.3; rv:41.0) Gecko/20100101 Firefox/41.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://www.computerbase.de/downloads/systemtools/all-in-one-runtimes/
Cookie: _ga=GA1.2.1412997295.1444464576; _gat=1
Connection: keep-alive

HTTP/1.1 200 OK
Server: nginx
Date: Sat, 10 Oct 2015 08:10:43 GMT
Content-Type: application/octet-stream
Content-Length: 357922986
Last-Modified: Sun, 16 Aug 2015 10:33:11 GMT
Connection: close
Etag: "55d066e7-155578aa"
Accept-Ranges: bytes
----------------------------------------------------------

this is the code:

#include <String.au3>

$SOURCE = BinaryToString(InetRead('http://www.computerbase.de/downloads/systemtools/all-in-one-runtimes/'))
$TOKEN = _StringBetween($SOURCE, '<input type="hidden" name="token" value="', '">')
If @error <> 0 Then MsgBox(0, 'ERROR', 'TOKEN')
$TOKEN = $TOKEN[0]
$URLID = _StringBetween($SOURCE, '<input type="hidden" name="urlid" value="', '">')
If @error <> 0 Then MsgBox(0, 'ERROR', 'URLID')
$URLID = $URLID[0]

; Creating the object
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "http://www.computerbase.de/downloads/systemtools/all-in-one-runtimes/", False)
$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

; The data to be sent to page 1 (the one with small download button)
$sPD = 'token=' & $TOKEN & '&urlid=' & $URLID
MsgBox(0,'',$sPD)

; Performing the Request
$oHTTP.Send($sPD)

; Download the body response if any, and get the server status response code.
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status

If $oStatusCode <> 200 then
 MsgBox(4096, "Response code", $oStatusCode)
EndIf

$SOURCE = $oReceived
$TOKEN = _StringBetween($SOURCE, '<input type="hidden" name="token" value="', '">')
If @error <> 0 Then MsgBox(0, 'ERROR', 'TOKEN')
$TOKEN = $TOKEN[0]
$URLID = _StringBetween($SOURCE, '<input type="hidden" name="urlid" value="', '">')
If @error <> 0 Then MsgBox(0, 'ERROR', 'URLID')
$URLID = $URLID[0]
$oHTTP.Open("POST", "http://www.computerbase.de/downloads/systemtools/all-in-one-runtimes/", False)
$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

; The data to be sent to page 2 (the one with large download button)
$sPD = 'token=' & $TOKEN & '&urlid=' & $URLID & '&direct=1'
MsgBox(0,'',$sPD)

; Performing the Request
$oHTTP.Send($sPD) ;<-- At this point the "net activity" in the windows task manager is high for a few minutes...
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status

If $oStatusCode <> 200 then
 MsgBox(4096, "Response code", $oStatusCode)
EndIf

FileWrite('test.exe', $oReceived)

Exit

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi fasix,

Why do you want to do this and not host this file on a file hoster that supports direct link download?

It would be much simpler this way imho :)

Edited by Neutro

Share this post


Link to post
Share on other sites

hello, Neutro, thanks for the reply,

...because the problem it's to automate the download of the "Latest" version available in that moment, in case of need.

Share this post


Link to post
Share on other sites

Here using _IE* funcs seems much easier with less headache   :)

Share this post


Link to post
Share on other sites

hi, mikell, thanks for the tip.

you told me that with _IE* funcs it's possible to obtain this?

Location: http://ftp.computerbase.de/dl-758/dr9Vj4h9_HYzQ6dbwDwBDA/1444468243/aio-runtimes_v2.3.0.exe ;<-- FINAL URL

it's right?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0