2

Is there a way to work with the ResponseStream property of WinHttp.WinHttpRequest.5.1 in VBScript/ASP? At least the IStream interface (to which ResponseStream is related) is integrated into ASP to a certain degree.

Or is that the limit of what you can achieve in script? Requiring you to roll your own COM component if you want to go any further?

<html><body><h1>WinHttp</h1>
<%
Dim req, url, o
Set req = CreateObject( "WinHttp.WinHttpRequest.5.1" )
url = "http://www.google.de"
req.Open "GET", url, False
req.Send
Response.Write "<p>Hier kommt <code>" & url & "</code> :</p>"
Response.Write "<pre>"
Response.Write req.Status & " " & req.StatusText & VbNewLine
Response.Write req.GetAllResponseHeaders
Response.Write "</pre>"
' Response.Write Mid( req.ResponseText, InStr( req.ResponseText, "<div" ) )

' Set o = req.ResponseStream
' o = req.ResponseStream
' Same result for Write and BinaryWrite:
' VarType = 13, TypeName = Unknown
' ASP 0106 : 80020005; Typkonflikt; Unbehandelter Datentyp
' o = req.ResponseStream

' o = req.ResponseBody ' mit BinaryWrite
o = req.ResponseText ' mit Write
Response.Write "<p><code>IsObject " & IsObject(o)  & "</code></p>"
Response.Write "<p><code>IsNull "   & IsNull(o)    & "</code></p>"
Response.Write "<p><code>VarType "  & VarType(o)
Response.Write                  " " & TypeName(o)  & "</code></p>"
Response.Write o
' Response.BinaryWrite o
%>

Note that I know I can use either req.ResponseText or req.ResponseBody. The interest is in knowing whether you can go further in script using stuff that's only documented for C but maybe (speculating) accessible to script. I'm not knowledgeable about COM.

Lumi
  • 14,775
  • 8
  • 59
  • 92

1 Answers1

2

There is nothing you can do with an IStream directly in script code. All you could do is pass it to a COM object that might use it.

The IStream is very alien to Vbscript even in VB6 one has to jump through some fiery hoops to work with it.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • Thanks. Passing the thing to another COM object would be just fine. As [no doubt you are aware :)](http://bytes.com/topic/asp-classic/answers/828328-iis7-asp-response-object-incompatible-msxml-transformnodetoobject), the `Response` object implements `IStream` (at least partially), so I thought there might be a way of hooking them together. Somehow. Looks like I would have to delve into COM to go further in ASP. – Lumi Nov 30 '11 at 09:47
  • @Lumi: It would be nice to be able to use `CopyTo` or `Read` to pump contents of a stream to the `Response`. Sadly this not possible directly in VBScript. – AnthonyWJones Nov 30 '11 at 13:05
  • Yes, pumping data from COM object to COM object is what I thought would be nice to achieve. Did people back then write COM components to extend the possibilities of what could be done in VBScript? Or was accepting the shortcomings the prevalent pattern? Some components (like MSXML) are nicely integrated, others aren't. This must have sparked desire to obtain more nicely integrated components. – Lumi Nov 30 '11 at 16:55
  • 1
    Hello! I am looking to do something similar (with VBA, not VBScript, but similar enough). Can you give an example of how I can send the `ResponseStream` to another COM object (which COM object?) so that I can read a large HTTP response directly from the stream in real time? – Josh Jan 09 '13 at 13:38