[英]Meteor HTTP get the cookie from the response
This Meteor server side code sends a HTTP.call
and needs to get the value of the cookie from the response header.这个 Meteor 服务器端代码发送一个
HTTP.call
并需要从响应头中获取 cookie 的值。 I could not find clear doc showing how so I tried this which gave:我找不到明确的文档显示如何所以我尝试了这个,它给出了:
console.log('response: %j', response.headers.set-cookie);
cookie is not defined
cookie 未定义
But there is a cookie in the response body which looks like this但是响应正文中有一个 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"
}
How can I get that tasty cookie out of the response header?我怎样才能从响应头中得到那个美味的 cookie? Thanks
谢谢
Since minus sign can not be a part of JS variable name, the part set-cookie
is treated as a subtraction operator, yielding an error since cookie
variable is not defined.由于减号不能是 JS 变量名的一部分,因此
set-cookie
部分被视为减法运算符,由于未定义cookie
变量而产生错误。 Use dictionary syntax instead.请改用字典语法。
response.headers['set-cookie']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.