此 Meteor 服务器端代码发送一个 HTTP.call
并需要从响应 header 中获取 cookie 的值。我找不到明确的文档来说明我是如何尝试的:
console.log('response: %j', response.headers.set-cookie);
cookie is not defined
但是在响应体中有一个 cookie 看起来像这样
console.log('response: %j', response.headers);
{
"date": "Mon, 18 Apr 2016 23:18:58 GMT",
"x-frame-options": "SAMEORIGIN",
"pragma": "no-cache",
"cache-control": "no-cache",
"expires": "Thu, 01 Jan 1970 00:00:00 GMT",
"set-cookie": ["JSESSIONID=0000saKY2KAfxMD3sYcqgc8N11d:16poh0lr1; Path=/is"],
"p3p": "CP=\"CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE\"",
"keep-alive": "timeout=3, max=50",
"connection": "Keep-Alive",
"transfer-encoding": "chunked",
"content-type": "text/html;charset=ISO-8859-1",
"content-language": "en-US"
}
我怎样才能从响应 header 中取出美味的 cookies ?谢谢
最佳答案
由于减号不能作为 JS 变量名的一部分,set-cookie
部分被视为减法运算符,由于 cookie
变量不是定义。请改用字典语法。
response.headers['set-cookie']
关于javascript - Meteor HTTP 从响应中获取 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36706165/