[英]Get specific cookie from request headers (express)
I came across an issue today with express, assume we set several cookies, when I use request.headers
only one cookie is returned: 我今天遇到了一个快递问题,假设我们设置了几个cookie,当我使用
request.headers
仅返回一个cookie:
cookie: 'userSession=123'
for example, not only can't I use request.headers.cookie
as it is unreliable (users can have several cookies set), but I can't parse it into a JSON object (this is invalid json) nor can I select this cookie specifically, which leads to a subquestion, is this how we get cookies from express response, through headers? 例如,我不仅不能使用
request.headers.cookie
因为它不可靠(用户可以设置多个cookie),而且不能将其解析为JSON对象(这是无效的json),也不能选择它特别是cookie,这导致一个子问题,这是我们如何通过标头从快速响应中获取cookie?
您可以从$ npm install cookie-parser
使用cookieParser()
$ npm install cookie-parser
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.