1

How can I send binary data with the send method? Apparently it treats the data as a string and it stops when it encounters a NULL character, which is legal in binary data. And ultimately not all the data get sent. If so, how can I set the size of the data to be sent then?

Set oHTTP = Createobject( "WinHttp.WinHttpRequest.5.1" )
oHTTP.Open "PUT", myURL, False
oHTTP.Send binaryData

Suppose binaryData is read from a file for example, and it's size is binaryDataSize bytes.

Bite Bytes
  • 1,455
  • 8
  • 24

2 Answers2

3

You can send files using the ADODB.Stream object and a proper content-type header:

Const adTypeBinary = 1

Set request = CreateObject("WinHttp.WinHttpRequest")
Set dataStream = CreateObject("ADODB.Stream")

dataStream.Type = adTypeBinary
dataStream.Open
dataStream.LoadFromFile "C:\path\to\your.file"

request.Open "PUT", "http://your/url"
request.SetRequestHeader "Content-Type", "application/octet-stream"
request.Send dataStream
Tomalak
  • 332,285
  • 67
  • 532
  • 628
  • Thank's, I knew about ADODB but is it native to windows? or does it need some kind of installation? – Bite Bytes Dec 17 '18 at 16:54
  • 1
    No, that's native. (see MSDN https://learn.microsoft.com/en-us/sql/ado/reference/ado-api/stream-object-ado?view=sql-server-2017) – Tomalak Dec 17 '18 at 16:56
1

Unfortunately VBScript does not have proper routines for working with binary files. As a workaround you could use some approaches for reading binary files described here Read and write binary file in VBscript

If this still doesn't help then you could encode the data with base64 before sending Base64 Encode String in VBScript

montonero
  • 1,363
  • 10
  • 16