3

我们如何接收一个 cookie 作为响应和标头的“set-cookie”参数,然后在下一个请求中发送这个 cookie。所有这些都使用“http”模块而不是第 3 方模块。我基本上对我将如何处理感兴趣将cookie作为参数发布在即将进入下一个请求的标头中

4

2 回答 2

7

哦终于发现我的错误我没有在我的标题列表中包含cookie参数。我是这样写的:

var options = {host:url_parsed.host, path:url_parsed.path, method:'GET', 'Cookie':cookie, 'Accept':'/', 'Connection':'keep-alive', };

我实际上应该是这样的:

 var options = {host:url_parsed.host, path:url_parsed.path, method:'GET', headers:{'Cookie':cookie}, 'Accept':'/', 'Connection':'keep-alive', };
于 2013-08-18T00:22:46.310 回答
3

您可以像这样在标头中写入 cookie:

response.writeHead(200, {
    'Set-Cookie': 'mycookie=testvalue',
    'Content-Type': 'text/plain'
});
response.end('Hello World\n');
于 2013-08-14T05:39:54.007 回答