Downloading binary file using WinHttp.WinHttpRequest.5.1 - content is binary gibberish

1.6k Views Asked by At

I'm trying to download an MS Excel file (binary). I even get the correct response headers (see both images (httpfox and vbscript) attached). When trying to save objWinHttp.ResponseBody using the following function (found in many posts referring to download binary files):

Function SaveBinaryData (FileName, ByteArray)
  adTypeBinary = 1
  adSaveCreateOverWrite = 2

  SET BinaryStream = CreateObject("ADODB.Stream")

  BinaryStream.Type = adTypeBinary

  BinaryStream.Open
  BinaryStream.Write(ByteArray)

  BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
  BinaryStream = 0
  'BinaryStream.Close
  'Return SaveBinaryData
End Function

the file is being saved as gibberish with binary content.

Here is the Excel file if someone would like to see how the content looks like: https://dl.dropboxusercontent.com/u/17845471/mySrsExport.xls

1

There are 1 best solutions below

1
On BEST ANSWER

There's nothing inherently wrong with your code. Your file just isn't an Excel workbook, as @Bond already pointed out. It's a gzip-compressed HTML page. Save it as mySrsExport.htm.gz and you'll be able to extract the HTML file with gunzip or 7-Zip or some other (un)packer.