WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WinHttpRequest

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Download a Binary File

 Keywords: Download GET Binary File WinHttp WinHttpRequest BinaryAllocArray ADODB.Stream 

Sample 1:

;***************************************************************************
;**
;**  Code to download a binary file using  WinHttp.WinHttpRequest.5.1 anf BinaryAllocArray
;**
;***************************************************************************
strFile = "D:\Temp\wwctl44i.zip"
; Instantiate a WinHttpRequest object.
WinHttpReq = ObjectCreate("WinHttp.WinHttpRequest.5.1")
; Initialize an HTTP request.
WinHttpReq.Open("GET", "http://files.winbatch.com/wwwftp/wb01/wwctl44i.zip", @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
Exit


Sample 2:

;***************************************************************************
;**
;**  Code to download a binary file using  WinHttp.WinHttpRequest.5.1 and ADODB.Stream
;**
;***************************************************************************

#DefineFunction SaveBinaryData(FileName, ByteArray)
  adTypeBinary = 1
  adSaveCreateOverWrite = 2
  ;Create Stream object
  BinaryStream = ObjectCreate("ADODB.Stream")
  ;Specify stream type - binary data.
  BinaryStream.Type = adTypeBinary
  ;Open the stream And write binary data To the object
  BinaryStream.Open
  BinaryStream.Write(ByteArray)
  ;Save binary data To disk
  BinaryStream.SaveToFile(FileName, adSaveCreateOverWrite)
  BinaryStream = 0
  Return
#EndFunction

; Instantiate a WinHttpRequest object.
WinHttpReq = ObjectCreate("WinHttp.WinHttpRequest.5.1")
; Initialize an HTTP request.
WinHttpReq.Open("GET", "http://files.winbatch.com/wwwftp/wb01/wwctl44i.zip", @FALSE)
; Send the HTTP request.
WinHttpReq.Send()
; Display the response text.
ByteArray =  WinHttpReq.ResponseBody
SaveBinaryData("d:\temp\wwctl44i.zip", ByteArray)
; Clean up
WinHttpReq  = 0
Exit

Article ID:   W18207
Filename:   Download a Binary File.txt
File Created: 2009:08:19:09:33:28
Last Updated: 2009:08:19:09:33:28