Checking if another web server is listening from asp

雨燕双飞 提交于 2019-12-25 00:11:36

问题


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?


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/91223/checking-if-another-web-server-is-listening-from-asp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!