简体   繁体   English

Google Chrome未设置从NodeJS / Express服务器发送的Cookie

[英]Google Chrome not setting cookie sent from NodeJS/Express server

I am trying to set up authenticated endpoints in my backend(Express/Node/Mongo with express-session) and can send a cookie to the client (Chrome Version 53.0.2785.143) in the Response Header but when I look for the cookie in the Dev Console under Application->Storage->Cookies-> http://localhost:8100 it is not there, and so nothing is sent back to the server in subsequent Request Headers. 我正在尝试在后端(带有Express-Session的Express / Node / Mongo)中设置经过身份验证的端点,并且可以在响应标题中将Cookie发送给客户端(Chrome版本53.0.2785.143),但是当我在开发控制台在“应用程序”->“存储”->“ Cookies”->“ http:// localhost:8100”下不存在,因此在后续的请求标头中没有任何内容发送回服务器。 However, when I test the code as written using Postman it appears that everything works meaning that the server sends a cookie on login and the cookie is returned when I GET authenticated endpoints. 但是,当我测试使用Postman编写的代码时,似乎一切正常,这意味着服务器在登录时发送一个cookie,并且当我获取经过身份验证的终结点时返回该cookie。

Response Headers
HTTP/1.1 200 OK
X-Powered-By: Express
Vary: X-HTTP-Method-Override
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: DELETE, PUT, GET
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
Content-Type: application/json; charset=utf-8
Content-Length: 1258
ETag: W/"4ea-X9Q0hp8ptccLVapzMZamYA"
set-cookie: connect.sid=s%3AyEaCZPUtH-rA0yQ3Osk-FNBHxQNYbFqp.gvwe%2FO0GSSfaX6i8Y29XD9vEo6ht2M%2FqL00wiFpntnU; Path=/
Date: Tue, 25 Oct 2016 01:28:59 GMT
Connection: keep-alive

Request Headers
POST /login HTTP/1.1
Host: localhost:8000
Connection: keep-alive
Content-Length: 51
Pragma: no-cache
Cache-Control: no-cache
Origin: http://localhost:8100
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36
Content-Type: application/json
Accept: */*
Referer: http://localhost:8100/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8

Request Payload
{"email":"test9876@gmail.com","password":"test123"}

Settings object for the session ID cookie:
{ path: '/', _expires: null, originalMaxAge: null, httpOnly: false }

session ID cookie name = 'connect.sid'.

Ionic2 service to login user.
public loginUser(user:Object):Observable<any>{
    let headers = new Headers();
    headers.append('Content-Type', 'application/json');
    return this.http.post('http://localhost:8000/login', JSON.stringify(user), {headers: headers})
            .map(this.extractData)
            .catch(this.handleError)
}

public extractData(res: Response) {
    console.log(res.headers); //cookie does not log here in response
    let body = res.json();
    return body || { };
}

Usually, chrome won't save cookies for localhost. 通常,chrome不会为本地主机保存Cookie。 Please disable your web security in chrome. 请在Chrome中禁用您的网络安全。

How to disable chrome web security ? 如何禁用Chrome Web安全性?

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir="C:/Chrome dev session" --args --disable-web-security

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

相关问题 无法读取从 Express 服务器上的 React js 前端发送的 cookie - Unable to read cookie sent from React js frontend on Express server 未从服务器发送环境变量。 Nodejs,表达EJS - Environment varaible not being sent from server. Nodejs, express EJS 设置 audio.currentTIME; 带有从 express 服务器发送的歌曲缓冲区 - setting audio.currentTIme; with song buffer sent from express server 从后端 API (nodeJS express) 发送到 forntend (NextJS) 的 Cookie 未在浏览器中设置 - Cookie sent from backend API (nodeJS express) to forntend (NextJS) is not being set in the browser res.cookie(名称,值); 不设置 cookie (Express/NodeJs) - res.cookie(name,value); Not setting cookie (Express/NodeJs) 快递不设置Cookie - Express not setting Cookie 无法在客户端访问或删除 Express 发送的 Cookie - Can't Access or Delete Cookie sent from Express in Client 服务器发送的事件在 chrome devtools 中显示为空白,用于简单的快速 SSE - Server sent events showing blank in chrome devtools for simple express SSE NodeJS / express 4:在写入cookie时发送标题后无法设置标题 - NodeJS/express 4 : Can't set headers after they are sent while writing cookie 为什么浏览器没有设置从我的 node.js 后端发送的 cookie? - Why browser is not setting the cookie sent from my node js backend?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM