0

I'm trying to make a GET with a Cookie but it's not working in my node.js program. However, the GET works fine from POSTman in chrome. Why could this be? The error I get back is 'Access denied for user anonymous'. I believe that's because this particular API expects a Cookie with session_id=xxxxxxx which I am trying to pass like this:

rest.get(<theurl>, {'headers':{'Cookie':<session_id=xxxx>}}.on('complete'.....

The only thing I can think of is the session_id=xxx is not being correctly put into the JSON object as a variable. But I'm new to node and javascript so I don't know how to debug other than putting console.log() all over the place. Any ideas out there?

Barodapride
  • 3,475
  • 4
  • 25
  • 36

2 Answers2

1

Something like this:

var options = { 
    hostname: 'example.com',
    path: '/somePath.php',
    method: 'GET',
    headers: {'Cookie': 'myCookie=myvalue'}
};
var results = ''; 
var req = http.request(options, function(res) {
    res.on('data', function (chunk) {
        results = results + chunk;
        //TODO
    }); 
    res.on('end', function () {
        //TODO
    }); 
});

req.on('error', function(e) {
        //TODO
});

req.end();
Stuart Siegler
  • 1,686
  • 4
  • 30
  • 38
1

Cookie without quote, like this:

rest.get(<theurl>, {headers:{Cookie:<session_id=xxxx>}}.on('complete'.....
ccw1078
  • 31
  • 4