request.js/examples/follow-redirect.js

17 lines
643 B
JavaScript
Raw 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('../');
// will redirect to https://www.github.com and then https://github.com
2018-06-19 06:17:04 +00:00
//request('http://www.github.com', function (error, response, body) {
request({ uri: { protocol: 'http:', hostname: 'www.github.com' } }, function (error, response, body) {
2018-06-19 01:39:19 +00:00
if (error) {
console.log('error:', error); // Print the error if one occurred
return;
}
console.log('statusCode:', response.statusCode); // The final statusCode
2018-06-19 06:17:04 +00:00
console.log('Final href:', response.request.uri.href); // The final URI
2018-06-19 01:39:19 +00:00
console.log('Body Length:', body.length); // body length
});