0

I'm trying to retrieve some information from the response that npm Request generated. I'm able to retrieve information like "statusCode" by typing "response.statusCode". However if I want to retrieve other information like "redirectUri", it would show undefined. How am I able to retrieve "redirectUri"?

Below is the code to get the response from the URL that I'm testing;

var request = require('request');

var getRequest = function (url, index) {              
        request(url, function (error, response, body) {
            console.log(response.redirectUri);
        });
}  

getRequest('https://www.exampleUrl.com', 1); 

Below are some of the information from the response;

redirects: [
{ statusCode: 302,
 redirectUri:'https://www.exampleurl'.....etc 
}],

Please see the response in attached image Note: I have blurred out the url that I'm testing.

Community
  • 1
  • 1
  • You say **Below are some of the information from the response;** -- where is that info coming from? I don't see you trying to access that in your code. Is that part of the data you get from the response? – Katie.Sun Dec 03 '18 at 01:00
  • @Katie.Sun, the info is coming from the "getRequest" function. I have added the code to call "getRequest" function. Please see above. Yes, "redirects" is part of the data that I'm getting from the response. – Mandy Wells-Lakeland Dec 03 '18 at 04:02
  • I found my answer from https://stackoverflow.com/questions/16687618/how-do-i-get-the-redirected-url-from-the-nodejs-request-module. Thank you! :) – Mandy Wells-Lakeland Dec 03 '18 at 07:12

1 Answers1

0

I found my answer from How do I get the redirected url from the nodejs request module?. Set "followRedirect: false" and use "response.headers.location".

var url = 'http://www.google.com';
request({ url: url, followRedirect: false }, function (err, res, body) {
console.log(res.headers.location);
});