How to save byte stream as binary document

How to save byte stream as binary document

am 02.04.2007 23:50:26 von eengel

Hi,

A site Im working with has an API that allows one to retrieve files.
The file is a Word doc sent as a byte stream.

url="blah.asp?fileid=777777"
set oXMLHTTP=server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
oXMLHTTP.open "POST",url,false
oXMLHTTP.send
binData=oXMLHTTP.responseText

I am trying to save the stream as a file on the Web server. It isn't
working. I've tried using FS.OpenTextFile, Stream.Write, etc.
Nothing is working.

Anyone have any sample code on how to do this?
Thanks

Re: How to save byte stream as binary document

am 03.04.2007 10:13:27 von Anthony Jones

wrote in message
news:1175550626.919355.160150@q75g2000hsh.googlegroups.com.. .
> Hi,
>
> A site Im working with has an API that allows one to retrieve files.
> The file is a Word doc sent as a byte stream.
>
> url="blah.asp?fileid=777777"
> set oXMLHTTP=server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
> oXMLHTTP.open "POST",url,false
> oXMLHTTP.send
> binData=oXMLHTTP.responseText
>
> I am trying to save the stream as a file on the Web server. It isn't
> working. I've tried using FS.OpenTextFile, Stream.Write, etc.
> Nothing is working.
>
> Anyone have any sample code on how to do this?
> Thanks
>

Dim oWinHTTP
Dim oStream

Set oWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")

oWinHTTP.Open "GET", "blah.asp?fileid=777777", False
oWinHTTP.Send

If oWinHTTP.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write oWinHTTP.responseBody
oStream.SaveToFile "c:\temp\blah777777.doc"
oStream.Close
End If

BTW, Are you sure you need a POST ? Your not sending any data in the send
then GET would be more appropriate.