【发布时间】:2014-04-28 17:16:37
【问题描述】:
我想知道如何将 cookie 与 request (https://github.com/mikeal/request) 一起使用
我需要设置一个 cookie,它可以从请求中为每个子域获取,
类似
*.examples.com
路径适用于每个页面,例如
/
然后服务器端能够正确地从 cookie 中获取数据,例如
测试=1234
我发现从响应中设置的 cookie 工作正常,
我添加了一个自定义 jar 来保存 cookie,类似于
var theJar = request.jar();
var theRequest = request.defaults({
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36'
}
, jar: theJar
});
但是我根据请求设置的 cookie,只能在同一个域中获取,
我找不到在更多选项中设置 cookie 的方法
现在,如果我想要一个可以在三个子域中获取的 cookie,
我必须这样设置:
theJar.setCookie('test=1234', 'http://www.examples.com/', {"ignoreError":true});
theJar.setCookie('test=1234', 'http://member.examples.com/', {"ignoreError":true});
theJar.setCookie('test=1234', 'http://api.examples.com/', {"ignoreError":true});
这里有任何从请求中设置 cookie 的高级方法吗,
使其能够在每个子域中获取???
【问题讨论】: