2

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.

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thank's, I knew about ADODB but is it native to windows? or does it need some kind of installation?
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.