我想知道如何在请求中使用cookie (https://github.com/mikeal/request)
我需要设置一个Cookie,该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的任何高级方法吗,
使它能够在每个子域中提取???
我刚刚找到了解决方法....
theJar.setCookie('test=1234; path=/; domain=examples.com', 'http://examples.com/');
嗯...我不得不说,要索取的文件不是很好...,大声笑
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句