So, I got an API, but I decided to switch from nano to using request . However, for some reason I cannot force the cookie to send the server back. Here is an example of the code I tested.
var request = require('request')
var cookieJar = request.jar();
var myCookie;
request({
method: 'POST',
uri: 'http://127.0.0.1:5984/_session',
form: {
name: 'test',
password: 'test123'
}
},
function(err, res, body) {
if (err) { console.log(err) };
console.log(res.statusCode);
console.log(res.headers);
console.log(body);
myCookie = request.cookie(res.headers['set-cookie'][0]);
cookieJar.setCookie(myCookie, 'http://127.0.0.1:5984/_session');
});
request({
method: 'GET',
uri: 'http://127.0.0.1:5984/db',
jar: cookieJar
},
function(err, res, body) {
if (err) { console.log(err) };
console.log(cookieJar);
console.log(res.statusCode);
console.log(res.headers);
console.log(body);
});
As you can see, I can get and set a cookie, but I was not authorized in the GET request. I cannot understand what I am doing wrong. Any advice or help would be greatly appreciated.
source
share