Verifica se un altro web server è in ascolto da asp
-
01-07-2019 - |
Domanda
Sto usando Microsoft.XMLHTTP per ottenere alcune informazioni da un altro server da un vecchio ASP/VBScript sito.Ma che altri server viene riavviato abbastanza spesso, quindi voglio controllare che fino e in esecuzione prima di tentare di estrarre informazioni da esso (o evitare la mia pagina dà HTTP 500 rilevando il problema in qualche altro modo).
Come posso fare questo con ASP?
Soluzione
Tutto quello che dovete fare è di avere il codice di continuare in caso di errore, quindi post su altro server e di leggere lo stato del post.Qualcosa di simile a questo:
PostURL = homelink & "CustID.aspx?SearchFlag=PO"
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.3.0")
on error resume next
xmlhttp.open "POST", PostURL, false
xmlhttp.send ""
stato = xmlhttp.stato
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
Altri suggerimenti
Si potrebbe provare a fare un ping al server e controllare la risposta.Date un'occhiata a questo articolo.