WinHttpRequest save as zip file Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Loop
Posts: 56
Joined: 07 Jan 2019, 14:51

WinHttpRequest save as zip file

08 Aug 2020, 09:40

Hi

wants to download a Zip file via WinHttpRequest, but only gets Zip headers (";PK") saved
How can I save as a Zip file?

Thanks

myCode:

Code: Select all

myUrl := "https://www.test.com/stocks"
myAuth := "Basic ...."

oHTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
oHTTP.Open("GET", myUrl , true)
oHTTP.SetRequestHeader("Authorization" , myAuth)
oHTTP.Send()
oHTTP.WaitForResponse()
myZipFile := oHTTP.ResponseText()
FileAppend, %myZIpFile%, zip.zip
Ahk_fan
Posts: 101
Joined: 31 Aug 2018, 14:34

Re: WinHttpRequest save as zip file

10 Aug 2020, 15:28

Hi,


I use an other function DownloadToFile from @Bentschi
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3291&p=16243
regards,
AHK_fan :)
Loop
Posts: 56
Joined: 07 Jan 2019, 14:51

Re: WinHttpRequest save as zip file

11 Aug 2020, 06:51

Thanks for answers, I have tried the mentioned examples, unfortunately without success.

Code: Select all

#SingleInstance,Force
url := "xxx"
Global auth := "xxx"

FileAppend, % URLDownloadToVar(url), zip.zip


URLDownloadToVar(url){
	hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
	hObject.Open("GET",url)
	hObject.SetRequestHeader("Authorization" , auth)
	hObject.Send()
	return hObject.ResponseText
}
teadrinker
Posts: 1786
Joined: 29 Mar 2015, 09:41
Contact:

Re: WinHttpRequest save as zip file  Topic is solved

11 Aug 2020, 10:49

Code: Select all

myUrl := "https://www.test.com/stocks"
myAuth := "Basic ...."

oHTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
oHTTP.Open("GET", myUrl , true)
oHTTP.SetRequestHeader("Authorization" , myAuth)
oHTTP.Send()
oHTTP.WaitForResponse()
arr := oHTTP.responseBody

pData := NumGet(ComObjValue(arr) + 8 + A_PtrSize)
length := arr.MaxIndex() + 1

File := FileOpen("zip.zip", "w", "cp0")
File.RawWrite(pData + 0, length)
File.Close()
Loop
Posts: 56
Joined: 07 Jan 2019, 14:51

Re: WinHttpRequest save as zip file

11 Aug 2020, 11:20

@teadrinker thank you very much, Perfect !

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Albireo, Azev, effel, Google [Bot] and 52 guests