tags:

views:

153

answers:

2

I'm using Microsoft.XMLHTTP to get some information from another server from an old ASP/VBScript site. But that other server is restarted fairly often, so I want to check that it's up and running before trying to pull information from it (or avoid my page from giving an HTTP 500 by detecting the problem some other way).

How can I do this with ASP?

A: 

You could try making a ping to the server and check the response. Take a look at this article.

Jordi
+1  A: 

All you need to do is have the code continue on error, then post to the other server and read the status from the post. Something like this:

PostURL = homelink & "CustID.aspx?SearchFlag=PO"
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.3.0")

on error resume next

xmlhttp.open "POST", PostURL, false
xmlhttp.send ""

status = xmlhttp.status

if err.number <> 0 or status <> 200 then
    if status = 404 then
        Response.Write "ERROR: Page does not exist (404).<BR><BR>"
    elseif status >= 401 and status < 402 then
        Response.Write "ERROR: Access denied (401).<BR><BR>"
    elseif status >= 500 and status <= 600 then
        Response.Write "ERROR: 500 Internal Server Error on remote site.<BR><BR>"
    else
        Response.write "ERROR: Server is down or does not exist.<BR><BR>"
    end if
else
    'Response.Write "Server is up and URL is available.<BR><BR>"
    getcustomXML = xmlhttp.responseText
end if
set xmlhttp = nothing
And turn off on error resume next with On Error Goto 0 at the end there....
Mark Brackett