PDA

View Full Version : VBA winHTTP in async mode



Adraen
09-03-2012, 05:12 AM
Hi everybody,

I tried to search the forum for a similar question, however, I was not able to find any async related questions.

So I am trying to use winhttp to do async http request, I have declared the object with WithEvents and defined a couple of events howerver they are not triggered :/.

I have checked with a packet sniffer that my server was sending the data as expected.

I have joined the file to this post if someone can take a quick look :).

The calling code is the function Test in the module Module1 (I will refactor everything when I code this working ^^). The main logic for the event handling is in the class module AsyncMessageDispatcher.

thanks !

Kenneth Hobs
09-04-2012, 09:36 AM
Welcome to the forum!

I don't know what you need. Can you say what the goal is? I hope that you added a dummy login and password to test. I don't know what testing should show.

Have a look at this thread. You probably need to wait for a response. http://www.vbaexpress.com/forum/showthread.php?t=43237

Adraen
09-04-2012, 10:25 AM
Hi thanks for the reply !

I am trying to write an instant messenger for Excel, not really useful but a fun project ! Excel will transfer messages to a nodejs backend using json.

The login is just my username and of course the pasword is fake :) (I use something a bit more complicated).

From the link you've posted, winHttp is used in synchronous mode (third parameter is false) if you set it to true it becomes asynchronous and event are supposed to be triggered to notify of certain events, such as reception of a response.

Best regards

Crocus Crow
09-04-2012, 01:25 PM
Have a look at http://www.tushar-mehta.com/publish_train/xl_vba_cases/vba_web_pages_services/#_Toc173749363. It uses XMLhttp asynchronously.

Adraen
09-04-2012, 02:06 PM
Hi Crocus,

thanks for the reply I did get xmlHTTP working previously in async mode, however, I was expecting winHttp to be more lightweight(as it doesn't require any of the XML parsing libs) but if it is the only way to go at the moment I think I will use that.

Thanks !

Crocus Crow
09-05-2012, 07:40 AM
I found this code - http://stagesolutions.wordpress.com/2012/04/18/asynchronous-download-from-http-with-vba/ - which uses WinHttpRequest asynchronously, with event raising.