Forum Moderators: open

Message Too Old, No Replies

check the existance of an url

         

jss_eng

10:18 am on Apr 13, 2004 (gmt 0)

10+ Year Member



hi guys

i just want to know how i can check the existance of an url using asp

duckhunter

3:36 pm on Apr 13, 2004 (gmt 0)

10+ Year Member



You can use the XMLHTTP object in classic ASP

On Error Resume Next
set xmlobj = Server.CreateObject("Microsoft.XMLHTTP")
xmlobj.open "GET", "http://www.someURL.com/Default.asp", False
xmlobj.send ""
strStatus = xmlobj.Status
strRetval = xmlobj.responseText
set xmlobj = nothing

If strStatus = 404 Then
Response.Write "URL Not Found"
ElseIf strStatus <> 200 Then
Response.Write "Error Connecting to URL. Status: " & strStatus
else
Response.Write "Success"
End If

And most of the status codes that should be returned can be found here: [support.microsoft.com ]

Note: A custom 404 page that does not add the 404 status in the Response will return a status of 200 so careful if the site you hit redirects to a custom 404. It appears to the object all HTTP traffic occurred normally.

jss_eng

1:04 am on Apr 18, 2004 (gmt 0)

10+ Year Member



thank you so much
the code worked correctly

regards