COM Error in Web File Copy Code

Started by limnos, November 29, 2018, 01:28:06 PM

Previous topic - Next topic

limnos

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)

limnos

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)

td

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? 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade