简体   繁体   English

响应标头中的Set-Cookie未保存到浏览器cookie存储中

[英]Set-Cookie in response header is not saved into browser cookie storage

the response header is 响应头是

Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Origin, X-Requested-With, x-request, Content-Type, Accept
Access-Control-Allow-Origin:*
Cache-Control:private
Connection:close
Content-Length:100
Content-Type:application/json; charset=utf-8
Date:Tue, 14 Feb 2017 02:45:56 GMT
Server:nginx/1.2.8
Set-Cookie:USER=6ae633831f39447688892e6b2b156cec; Max-Age=604800; Path=/
Set-Cookie:USERINFO=298967; Max-Age=604800; Path=/
X-Powered-By:node.js
X-Ua-Compatible:chrome=1

the cookie format's right (used cookie package to serialize ). cookie格式的权利(用于序列化的cookie包)。 the server is developed by node.js. 服务器由node.js开发。

not only chrome, Firefox doesn't work too. 不仅是Chrome,Firefox也不行。 the document.cookie is empty and also i can't see cookie in application section of chrome developer tool. document.cookie是空的,我也看不到chrome开发工具的应用程序部分中的cookie。

Any wrong in response header ?? 响应头有什么问题? Please help . 请帮忙 。

This problem occur due to multiple responses from server to client. 由于服务器到客户端的多个响应,会出现此问题。

For example if you are sending a response to the server using response.send() and same time using you are using response.setHeader() 例如,如果您使用response.send()向服务器发送响应,并且同时使用response.setHeader()

This problem can be solve by creating cookie in client side using javascript. 通过使用javascript在客户端创建cookie可以解决此问题。 And reading its value from node.js 并从node.js中读取它的值

答案是因为我使用了必须通过{credentials =>'same-origin'}选项的fetch()API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM