Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何从量角器中的函数返回值?_Node.js_Protractor_Httprequest - Fatal编程技术网

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);
});