Search code examples
vbaexcelhttprequestwinsockwinhttp

VBA for "HTTP GET" request, through an unknown proxy?


Put simply, I'm trying to write some Excel VBA code that will "notify" a web server when a specific task is successful.

I am thinking the easiest way to interface with my web server is via an "HTTP GET" request.

Assuming that to be true, I have had some success using the library "Microsoft WinHTTP Services". However, this doesn't work through my company's proxy.

I'm coming back to this problem after a few weeks of ignoring it hoping people will forget about it (!) and can't recall every step I've tried sorry, but from memory: I have seen where I can specify my proxy settings when using WinHTTP, but what I can't work out is how to READ whatever my current proxy settings are (i.e. for cases where I don't know my proxy settings)

Reason being, this tool has to work for a global company: so short of building some sort of lookup table for proxy settings used in different parts of the world (and the headache of maintaining that), I need to either read the current proxy setting or use some other method.

Another method someone suggested was using the WinSock API. I'm not particularly au fait with API calls (unless I can Google and steal other people's!) and I can't find an example of using WinSock for HTTP GET requests. The WinSock documentation is a bit closer to the metal than my skill-set can handle!

Can someone please help either:

  • Advise how I can read my current proxy settings in order to feed in to WinHTTP, or
  • Help get me on track with an alternate method, perhaps using WinSock

Thanks a lot for your help,

Simon


Solution

  • You could try using the XMLHTTP60 object from MSXML2 v6.0 (or equivalent from earlier versions). This is designed to be a client-side object and should discover the proxy settings for itself.

    Add a reference to "Microsoft XML, v6.0" and then it's as simple as:

    Dim xhrRequest As XMLHTTP60
    
    Set xhrRequest = New XMLHTTP60
    xhrRequest.Open "GET", "<URL goes here>", False
    xhrRequest.send
    

    More info on MSDN here