Node.js 如何从量角器中的函数返回值?
在上面的代码中,我想从函数返回令牌变量,并将其存储在测试页面上的另一个变量中, 像 或 如何返回令牌并将其存储在变量中,并使用令牌变量调用另一个函数Node.js 如何从量角器中的函数返回值?,node.js,protractor,httprequest,Node.js,Protractor,Httprequest,在上面的代码中,我想从函数返回令牌变量,并将其存储在测试页面上的另一个变量中, 像 或 如何返回令牌并将其存储在变量中,并使用令牌变量调用另一个函数 this.httpXsrf = function() { var token; var http = require("https"); var options = { "method" : "GET", "hostname" : "infomatrix-ci.cmxdev.com",
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();
};
var token = apiPage.httpxsrf();
apiPage.httpxsrf().then(function(token){
// call another function like apiPage.httplogin(token);
});