WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: limnos on November 29, 2018, 01:28:06 PM

Title: COM Error in Web File Copy Code
Post by: limnos on November 29, 2018, 01:28:06 PM
Not great at object code work, but with some help getting closer.  Trying to copy down a zip file from a web link and unzip it.  I'm getting a COM oject\Memory error on this line: varByteArray = WinHttpReq.ResponseBody.  Any idea why that is happening and what the fix would be?

strFile = "%localpath%"
; Instantiate a WinHttpRequest object.
WinHttpReq = ObjectCreate("WinHttp.WinHttpRequest.5.1")
; Initialize an HTTP request.
WinHttpReq.Open("GET", "%targetfile%", @FALSE)
; Send the HTTP request.
WinHttpReq.Send()
; Display the response text.
varByteArray = WinHttpReq.ResponseBody
buf = BinaryAllocArray(varByteArray)
data = BinaryWrite(buf, strFile)
BinaryFree(buf); Clean up
WinHttpReq  = 0
timedelay(1)
zUnZipFiles("u o d", "%localpath%", "*.*", "", "%unziploc%")
timedelay(1)
Title: Re: COM Error in Web File Copy Code
Post by: limnos on November 29, 2018, 01:30:06 PM
I tried using this code instead, but it still chokes with a COM error on WinHttpReq.ResponseBody

num="0"
strFile = "%localpath%"
; Instantiate a WinHttpRequest object.
WinHttpReq = ObjectCreate("Microsoft.XMLHTTP")
; Initialize an HTTP request.
WinHttpReq.Open("GET", "%targetfile%", @FALSE)
; Send the HTTP request.
WinHttpReq.Send()
num = WinHttpReq.Status
If num == "200" then
   oStream = ObjectCreate("ADODB.Stream")
   oStream.Open
   oStream.Type = 1
   oStream.Write WinHttpReq.ResponseBody
   oStream.SaveToFile(strFile)
   oStream.Close
Endif
timedelay(1)
zUnZipFiles("u o d", "%localpath%", "*.*", "", "%unziploc%")
timedelay(1)
Title: Re: COM Error in Web File Copy Code
Post by: td on November 29, 2018, 02:24:58 PM
Your problem has more than one possible cause.  It could be that you need to set specific request header information, your file URL is incorrect, or you are attempting to download a massive (gigabytes) file.  Don't know which if any of these it might be.  What exactly is the text of the error including what you see by pressing the "More Error Info" button?