request.js/examples/no-follow-redirect.js

17 lines
641 B
JavaScript
Raw Permalink Normal View History

2018-06-19 01:39:19 +00:00
'use strict';
2018-06-19 07:55:40 +00:00
//var request = require('request-lite');
2018-06-19 01:39:19 +00:00
var request = require('../');
// would normally redirect to https://www.github.com and then https://github.com
request({ uri: 'https://www.github.com', followRedirect: false }, function (error, response, body) {
if (error) {
console.log('error:', error); // Print the error if one occurred
return;
}
2018-06-19 06:17:04 +00:00
console.log('href:', response.request.uri.href); // The final URI
2018-06-19 01:39:19 +00:00
console.log('statusCode:', response.statusCode); // Should be 301 or 302
console.log('Location:', response.headers.location); // The redirect
console.log('Body:', body || JSON.stringify(body));
});