18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
Javascript HTTP Response
Hey guys!
Narayan, long time no chat!
So I've been working on a project here...and I'm a little confused and need your help.
I am building a script that performs a lot of searches, gathers that information, then heads to different sites and tries to find out if the sites are responding. (200/500/404) etc...(about 1350 sites gathered on the fly).
I know that Sahi injects it's own little things in the way, but I can't use that at this point. The higher ups want responses in the logs, to see what's going on. Using the api within sahi to do the logging, is not a good idea, cuz that would chew up disk space like crazy.
So i've been messing around with this idea:
<browser> var $req = new XMLHttpRequest();
//$req.open('GET', document.location, false);
$req.open('HEAD', window.location, false);
$req.send(null);
var $headers = $req.getAllResponseHeaders().toLowerCase();
var $chicken = $req.status;
//var $response = $req.getResponseHeader("Status");
_debug($headers);
_alert($chicken);
if ($chicken == 200)
{
_alert("BINGO");
} else {_alert("stop");};
</browser>
I never seem to get the "Stop" alert, even if i go to a page i KNOW doesnt exist. like www.afsdgsfdgsfgs.com
Got any ideas on how to help me out with this one? I've seen a lot of requests over the years for sahi to do something like this, and I think I am on to something. But if I am not mistaken, my above placed code is receiving responses from Sahi's server, not the web server...
Ideas?
Thank you!
Cory
Narayan, long time no chat!
So I've been working on a project here...and I'm a little confused and need your help.
I am building a script that performs a lot of searches, gathers that information, then heads to different sites and tries to find out if the sites are responding. (200/500/404) etc...(about 1350 sites gathered on the fly).
I know that Sahi injects it's own little things in the way, but I can't use that at this point. The higher ups want responses in the logs, to see what's going on. Using the api within sahi to do the logging, is not a good idea, cuz that would chew up disk space like crazy.
So i've been messing around with this idea:
<browser> var $req = new XMLHttpRequest();
//$req.open('GET', document.location, false);
$req.open('HEAD', window.location, false);
$req.send(null);
var $headers = $req.getAllResponseHeaders().toLowerCase();
var $chicken = $req.status;
//var $response = $req.getResponseHeader("Status");
_debug($headers);
_alert($chicken);
if ($chicken == 200)
{
_alert("BINGO");
} else {_alert("stop");};
</browser>
I never seem to get the "Stop" alert, even if i go to a page i KNOW doesnt exist. like www.afsdgsfdgsfgs.com
Got any ideas on how to help me out with this one? I've seen a lot of requests over the years for sahi to do something like this, and I think I am on to something. But if I am not mistaken, my above placed code is receiving responses from Sahi's server, not the web server...
Ideas?
Thank you!
Cory