Page 1 of 1

WinHttpRequest save as zip file

Posted: 08 Aug 2020, 09:40
by Loop
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

Re: WinHttpRequest save as zip file

Posted: 10 Aug 2020, 15:28
by Ahk_fan
Hi,


I use an other function DownloadToFile from @Bentschi
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3291&p=16243

Re: WinHttpRequest save as zip file

Posted: 11 Aug 2020, 06:51
by Loop
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
}

Re: WinHttpRequest save as zip file  Topic is solved

Posted: 11 Aug 2020, 10:49
by teadrinker

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()

Re: WinHttpRequest save as zip file

Posted: 11 Aug 2020, 11:20
by Loop
@teadrinker thank you very much, Perfect !