Meteor HTTP从响应中获取cookie

时间:2016-04-18 23:47:35

标签: javascript meteor

此Meteor服务器端代码发送HTTP.call,需要从响应头中获取cookie的值。我找不到明确的文档,显示我是如何尝试这样做的:

console.log('response: %j', response.headers.set-cookie);

  

未定义cookie

但是响应正文中有一个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"
}

如何从响应标题中获取美味的cookie?感谢

1 个答案:

答案 0 :(得分:1)

由于减号不能是JS变量名的一部分,因此将set-cookie部分视为减法运算符,因为未定义cookie变量而产生错误。请改用字典语法。

response.headers['set-cookie']