Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trapping XMLHTTP.Open errors

Status
Not open for further replies.

luzmedia

Programmer
Mar 25, 2002
7
0
0
FR
Can anyone please tell me how I can trap a "Page cannot be displayed" or "Page cannot be found" error when calling a URL with the Open method in XMLHTTP?

Here's what I want to be able to do:

--------------------------
Dim objXmlHttp, target_url
Set objXmlHttp = Server.CreateObject ("Msxml2.XMLHTTP")
target_url = "
If THIS_URL_RETURNS_A_PAGE_OF_HTML("target_url") Then

objXmlHttp.Open "GET", target_url, False
objXmlHttp.Send
do_some_work_on(objXmlHttp.ResponseText)

Else

Response.Write target_url & " is not available"

End If
-------------------------------

What I need is a definition for THIS_URL_RETURNS_A_PAGE_OF_HTML(url)

I'd be very grateful for any solutions.
Cheers
Charlie
 
"Page cannot be displayed" or "Page cannot be found"

those are very different errors. can you tell us which it is

____________________________________________________
[sub]Python????? The other programming language you never thought of!
thread333-584700[/sub]
onpnt2.gif
 
uncheck "show friendly HTTP errors in IE (eg:tools/advanced)
to show the actual errror occuring also

____________________________________________________
[sub]Python????? The other programming language you never thought of!
thread333-584700[/sub]
onpnt2.gif
 
Hi & thanks for your response.

What I'm looking for is a GENERAL method of returning TRUE if a URL returns a page of HTML (other than a server-generated error page, of course) and FALSE in all other cases - e.g. the URL doesn't exist, is unavailable just at the moment etc, etc

In other words, I'm not trying to debug a particular error, I'm trying to avoid falling over if I get ANY error...

Charlie

 
You can use the status property of the xmlhttp object to check the page status once it returns. Basically this gives you the numeric code returned to the browser, ie 200 means everything a'ok, anything else means problem (400,404, 500, etc)

So you could just check the status and if it isn't 200 then you haven't successfully loaded the html page.

-Tarwn

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
minilogo.gif alt=tiernok.com
The never-completed website
 
Thanks Tarwn for an excellent solution!
Cheers
Charlie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top