Jump to content

winhttp - download an exe file


Recommended Posts

Hi guys.I'am using this UDF https://github.com/dragana-r/autoit-winhttp/releases for http operations.I already make an auto-login script for a website which is required to download an exe file which is only available for premium users.Now I struggle download this file.the download location doesn't change so it should be simple.Do I need to delivier any extra information or can I please any example on how to do it?

Edited by Au3Builder
Link to comment
Share on other sites

Without more info it's really hard to give any good advice.
If you've managed to login then downloading a file should be fairly simple task. I've noticed that usually the problem users have is that they don't know they should reuse either connection or session handle for the new task.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Thanks for your reply.

I have written a new script,less complicated,should be good as an example.

I believe the file is downloading somehwere as it waits before shows second message. I have no idea how to choose the download location.Take a look please and if thats not a problem fix it.

all i want is download the file.

thanks

 

 

#include <WinHTTP.au3>
download()

func download()
   Global $hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36 OPR/30.0.1835.125")
   $hConnect =  _WinHttpConnect($hOpen,"http://www.aida64.com/")
  $request =  _WinHttpSimplerequest($hConnect,"GET","/downloads/latesta64xe","http://www.aida64.com/")
   _WinHttpAddRequestHeaders($hConnect,"Connection:Keep-Alive")
   _WinHttpAddRequestHeaders($hConnect,"Content-Language:en")
   _WinHttpAddRequestHeaders($hConnect,"Content-Encoding:gzip")
   _WinHttpAddRequestHeaders($hConnect,"Content-Type:text/html; charset=utf-8")
      _WinHttpAddRequestHeaders($hConnect,"Content-Length:5800")
MsgBox(0,'',$request)

_WinHttpAddRequestHeaders($hConnect,"Connection:Keep-Alive")
_WinHttpAddRequestHeaders($hConnect,"Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")

$hConnect2 =  _WinHttpConnect($hOpen,"http://download.aida64.com/")
  $request2 =  _WinHttpSimplerequest($hConnect2,"GET","/aida64extreme520.exe","http://download.aida64.com/")

  MsgBox(0,'',$request2)



_WinHttpCloseHandle($hConnect)

_WinHttpCloseHandle($hOpen)

EndFunc

 

 

Edited by Au3Builder
Link to comment
Share on other sites

This is what a network sniffer says.

GET /downloads/latesta64xe HTTP/1.1
Connection: Keep-Alive
Referer: http://www.aida64.com/
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36 OPR/30.0.1835.125
Host: www.aida64.com

 

 

GET /aida64extreme520.exe HTTP/1.1
Connection: Keep-Alive
Referer: http://download.aida64.com/
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36 OPR/30.0.1835.125
Host: download.aida64.com

 

Link to comment
Share on other sites

#include "WinHttp.au3"

; Initialize and get session handle
$hOpen = _WinHttpOpen()
; Get connection handle
$hConnect = _WinHttpConnect($hOpen, "http://download.aida64.com")
; Request
$hRequest = _WinHttpSimpleSendRequest($hConnect, Default, "aida64extreme520.exe")

; Download to file (it's in the same folder as your script)
$hFile = FileOpen(@ScriptDir & "\aida64extreme520.exe", 26)
FileWrite($hFile, _WinHttpSimpleReadData($hRequest))
FileClose($hFile)

; Close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

But why in the world would you use WinHttp.au3 for this? Use built-in InetGet().

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Thanks very much.I am testing my script right now.Why? Like I said before,I must be authorized on the website to download files from there. I only needed to know how to download an exe file.Ok then I will let u know if I still have a problem.

 

 

Edited by Au3Builder
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...