You can get the HTTP status easily using CasperJS. To get HTTP status see the below script. For getting the HTTP status, firstly we will open the site for which we want to get the HTTP status and after that we will use the utils.dump() function.
The utils module provides simple helper functions, some of them being very specific to CasperJS though. You can check the function references for utils module from CasperJS documentation link- The utils module
dump() method is used to dumps a JSON representation of passed argument to the standard output.
/** * Webkul Software. * * @category Webkul * @package Webkul_CasperJS * @author Shikha Bhardwaj * @copyright Copyright (c) 2010-2017 Webkul Software Private Limited (https://webkul.com) * @license https://store.webkul.com/license.html */ var casper = require('casper').create(); utils = require('utils'), http = require('http'), casper.start(); casper.thenOpen('http://oc.webkul.com/', function(response) { utils.dump(response.status); if (response == undefined || response.status >= 400) this.echo("failed", 'GREEN_BAR'); }); casper.on('http.status.404', function(resource) { this.echo('This url is 404: ' + resource.url, 'GREEN_BAR'); }); casper.run(function() { casper.exit(); });
Now you have to run the command and you will get your result-
casperjs file_name.js
After executing the script, you can get the HTTP status. Refer to below screenshot for the same-
In case of 404 HTTP status, it will show like this-