For Programmers: Free Programming Magazines  


Home > Archive > ASP > March 2004 > Q. How do i solve XMLHTTP failure?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Q. How do i solve XMLHTTP failure?
Andy B

2004-03-28, 9:55 pm

Below is some pretty standard code for obtaining HTML from an URL. The
problem with XMLHTTP as far as i can tell, is that there is no way to
handle error catching. The only thing i've seen close to this is the
Status property if else statement which i think i saw on the MS site.

<-- from spider.asp -->

// Get HTMLStream: choice of: MSXML2.ServerXMLHTTP,Microsoft.XMLHTTP
http_obj = Server.CreateObject("Microsoft.XMLHTTP");
http_obj.Open("GET", strURL, false);
http_obj.Send();
if ((http_obj.Status >= 400)&&(http_obj.Status<=599)) {
Response.Redirect("spider.asp");
} else {
strHTML = http_obj.responseText;
}

Essentially, I need the asp page to reload if the http_obj.Send()
method doesn't work. Should I be looking at something more robust than
as ASP script to do this? Would error handling be less of a problem
then?

Regards,
AndyB
Andy B

2004-03-28, 9:55 pm

coastalrocket@yahoo.co.uk (Andy B) wrote in message news:<f1523bf.0401150720.3aa464d1@posting.google.com>...
> Below is some pretty standard code for obtaining HTML from an URL. The
> problem with XMLHTTP as far as i can tell, is that there is no way to
> handle error catching. The only thing i've seen close to this is the
> Status property if else statement which i think i saw on the MS site.
>
> <-- from spider.asp -->
>
> // Get HTMLStream: choice of: MSXML2.ServerXMLHTTP,Microsoft.XMLHTTP
> http_obj = Server.CreateObject("Microsoft.XMLHTTP");
> http_obj.Open("GET", strURL, false);
> http_obj.Send();
> if ((http_obj.Status >= 400)&&(http_obj.Status<=599)) {
> Response.Redirect("spider.asp");
> } else {
> strHTML = http_obj.responseText;
> }
>
> Essentially, I need the asp page to reload if the http_obj.Send()
> method doesn't work. Should I be looking at something more robust than
> as ASP script to do this? Would error handling be less of a problem
> then?
>
> Regards,
> AndyB


This is the best solution i could find;
function testPost(strURL) {
var oHTTP = new ActiveXObject("Microsoft.XMLHTTP");
try {
oHTTP.open("GET", strURL, false);
oHTTP.send();
return oHTTP.responseText;
}
catch (e) {
Response.Redirect("spider.asp");
}
return null;
}

I'd like to hear any experts' views on the matter.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com