I've written a small VBS script to GET or POST an URL to a WinHTTP object and put its plain-text output to stdout -- any body text it needs should be send via stdin. Please note that it's a stand-alone VBS file, so there's no web involved whatsoever -- it's simply invoked with CSCRIPT SENDURL.VBS GET/POST <url> at a Command Prompt -- SENDURL.VBS is my script.

The problem is that if it times out, that causes an error, and the WinHTTP object's properties such as ResponseText all become invalid, so I want to have a wrapper class which captures the WInHTTP object's OnError event and handles it more gracefully. I have an XLSM which does all this with a wrapper class handling the events, and it works great, but I can't get the class I make in SENDURL.VBS to react to any events. How is this done?

I've Googled this for days, and all I see is stuff about some function called GetRef, which gets a pointer to a function, so I would do something like objWinHTTP.OnError = GetRef(<myErrorHandler>), but this only works in the context of a web page, not via the Command Prompt and CSCRIPT. I also read about WScript.ConnectObject, but that doesn't work either.

Here's the complete class. How can I get event handlers to work when the events happen? Many thanks!
Please Login or Register  to view this content.