简体   繁体   中英

How to get, on client side, statusCode? javascript

On server side I did redirect:

res.statusMessage = 'Attachment is encrypted'
return res.redirect("/printapprovals");

now I want check statusCode on the client side - I can see the status code on chrome tools:

Request
URL: http://localhost:3000/downloadFile/e98b8560-2164-11e6-9940-adcca17ecd7b
Request Method:GET Status Code:302 Attachment is encrypted Remote
Address:127.0.0.1:3000

Also a good solution for me - if we get statusCode on the route... but how?

var testRoute = function (req, res) {  
  return res.render('print_page', { data: data })
}

Are you looking for something like this

var https = require('https');

https.get('https://encrypted.google.com/', function(res) {
  console.log("statusCode: ", res.statusCode); // <======= Here's the status code
  console.log("headers: ", res.headers);

  res.on('data', function(d) {
    process.stdout.write(d);
  });

}).on('error', function(e) {
  console.error(e);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM