Reputation: 3733
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?
Upvotes: 0
Views: 490
Reputation: 31
Cookie without quote, like this:
rest.get(<theurl>, {headers:{Cookie:<session_id=xxxx>}}.on('complete'.....
Upvotes: 1
Reputation: 1736
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();
Upvotes: 1