this.httpXsrf = function() {
var token;
var http = require("https");
var options = {
"method" : "GET",
"hostname" : "infomatrix-ci.cmxdev.com",
"port" : null,
"path" : "/",
"headers" : {
"cache-control" : "no-cache",
}
};
http.request(options, function(res) {
var chunks = [];
var setcookie = res.headers["set-cookie"];
if (setcookie) {
setcookie.forEach(
function(cookiestr) {
if (cookiestr.indexOf('XSRF-TOKEN') > -1) {
var a = cookiestr.split(';');
token = a[1].splice;
}
});
}
res.on("data", function(chunk) {
chunks.push(chunk);
});
res.on("end", function() {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
}).end();
};
In above code i would like to return token variable from function and store it in antoher variable on test page, like,
var token = apiPage.httpxsrf();
or
apiPage.httpxsrf().then(function(token){
// call another function like apiPage.httplogin(token);
});
How can i return token and store in variable and call another function using token variable?
via hitesh jani
No comments:
Post a Comment