2

I found the bit of code below and have altered it for my use, the only problem is that if the website does not give a failed return or success the code never ends. (IE if the site is hanging)

is there any way to set a time out after the "HttpRequest.send" command. so if after 30 seconds there is no response it marks it as failed and moves on?

     Set HttpRequest = CreateObject("Msxml2.XMLHTTP") 
   HttpRequest.open "HEAD", "http://example.com/", False 
   On Error Resume Next 
   HttpRequest.send 
   If Err.Number <> 0 Then 
     WScript.Echo "Error : " & Err.Number & ": " & Err.Description 
   Else 
     WScript.Echo "HTTP status: " & HttpRequest.status & " " _ 
      & HttpRequest.statusText 
   End If 

cheers

OH this is VBA

Aaron

DevilWAH
  • 2,553
  • 13
  • 41
  • 57
  • it seems the time out can't be set on this. Does any one have a solution that will time out after about 30 seconds if the website is not responding correctly? – DevilWAH Feb 24 '12 at 13:15
  • Did you see http://www.dailydoseofexcel.com/archives/2006/10/09/async-xmlhttp-calls/ ? – Fionnuala Feb 24 '12 at 14:30

1 Answers1

2

Switch to "Msxml2.ServerXMLHTTP.3.0" then you can set timeouts for multiple conditions; http://msdn.microsoft.com/en-us/library/windows/desktop/ms760403(v=vs.85).aspx

Alex K.
  • 171,639
  • 30
  • 264
  • 288
  • I get a cant create active x object when I try this method. – DevilWAH Feb 24 '12 at 17:14
  • could this be becasue I am running 64bit office ?? or can you hep with why I cant get this working? – DevilWAH Feb 25 '12 at 15:52
  • now I have an issue with Proxy settings. ie I Need to use the same proxy server as would be running in IE. works using Msxml2.XMLHTTP but not "server"? – DevilWAH Feb 27 '12 at 16:18
  • See proxycfg /.setproxy - http://stackoverflow.com/questions/1041886/how-can-i-specify-a-proxy-configuration-using-microsoft-xmlhttp – Alex K. Feb 27 '12 at 16:36
  • cant run that on the desktops I need to, security restrictions :) lol. I can't use a defined proxy as it is auto detected in IE and will be different on all the devices. Seems crazy that Msxml2.XMLHTTP does not have a time out setting. – DevilWAH Feb 28 '12 at 10:22