<%
' Tell the script to continue running if an error occurs:
On Error Resume Next
Dim objWinHttp
Dim strHTML
Set objWinHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
' Syntax:
' .SetTimeouts(ResolveTimeout, ConnectTimeout, SendTimeout, ReceiveTimeout)
' The parameters are integers and specify the number of milliseconds to wait
' before timing out. For a detailed description checkout the documentation:
' http://msdn2.microsoft.com/en-us/library/aa384061.aspx
' The defaults are:
' objWinHttp.SetTimeouts 0, 60000, 30000, 30000
' Which means there is no timeout on name resolution, a 60 second timeout on
' connecting to the remote server, and 30 seconds each for sending the request
' and receiving the response.
' Depending on the timeouts you actually want it would probably look something
' more like this:
' objWinHttp.SetTimeouts 5000, 5000, 10000, 10000
' That's 5 seconds each to resolve and connect and 10 seconds each for the
' request and response.
' Since I'm trying to illustrate what happens when timeouts expire,
' I'm setting ridiculously low 1ms timeouts so that it's guaranteed to break:
objWinHttp.SetTimeouts 1, 1, 1, 1
objWinHttp.Open "GET", "http://www.yahoo.com/", False
objWinHttp.Send
' Check if an error occured:
If Err.Number <> 0 Then
' If you want, you can actually vary your processing based
' on the actual error. If you've implemented some sort of
' caching, the best thing to do might be to fall back to
' the previously cached version, but that really all depends
' on your application.
If Err.Number = -2147012894 Then
strHTML = "A Timeout Error Occurred:" & vbCrLf
Else
strHTML = "An Unknown Error Occurred:" & vbCrLf
End If
strHTML = strHTML & "Error Source: " & Err.Source & vbCrLf
strHTML = strHTML & "Error Number: " & Err.Number & vbCrLf
strHTML = strHTML & "Error Description: " & Err.Description
' If you'll be doing any further error checking then you
' should clear the error object.
Err.Clear
Else
strHTML = objWinHttp.ResponseText
End If
Set objWinHttp = Nothing
%>
<p><strong>Here's The Code:</strong></p>
<table border="1">
<tr><td>
<pre>
<%= Server.HTMLEncode(strHTML) %>
</pre>
</td></tr>
</table>