从“ Set-Cookie”标题中解析“ _session_id”

时间:2019-01-30 10:52:16

标签: javascript node.js

解析下面标头中的多个名称/值对的最优化方法是什么

Set-Cookie →_session_id=840ab97adf6d4bbd9b80041cf6f765ea; path=/; HttpOnly

此外,在Node.js中,有没有更简单的方法可以从Cookie中获取“ _ session_id” ?目前,我正在执行以下类似操作:

var https = require('https');

// do the POST call
var reqPost = https.request(options, function(res) {
    console.log("statusCode: ", res.statusCode);
    console.log("headers: ", res.headers);
    var cookies;
    for(var item in res.headers) {
        if(item === 'set-cookie')
        {
            cookies = res.headers[item];
            console.log("set-cookie: " + cookies);   
        }
      }

    res.on('data', function(d) {
        console.info('POST result:\n');
        process.stdout.write(d);
        console.info('\n\nPOST completed');
    });
});

0 个答案:

没有答案