简体   繁体   English

Restify和Angular JS都在不同的域上,如何使用Restify响应设置httponly cookie?

[英]Restify and Angular JS both are on different domain how can i set httponly cookie using restify response?

I am using REST architecture for a web application created in Restifyjs and Frontend of this is in Angular JS both are running on different domains. 我正在为在Restifyjs中创建的Web应用程序使用REST体系结构,而它的Frontend在Angular JS中都在不同的域上运行。 For example on my local restify is working on locahost:7000 and angular js is working on localhost:5000. 例如在我的本地restify上正在locahost:7000上工作,而angular js在localhost:5000.

I am calling the Login API from frontend and authenticate the user from restify server and sending a token which needs to be set in cookies so i am using this but its not working any idea why ? 我从前端调用Login API并从restify服务器验证用户身份,并发送需要在cookie中设置的令牌,因此我正在使用它,但为什么不起作用,为什么?

res.setHeader('Set-Cookie', 'mycookie=test;expires=Fri, 13 Jun 2017 02:34:20 GMT;domain=localhost;path=/');

It's hard to say without seeing more code, but my guess is that you have already sent body content to the browser before your setHeader gets called. 没有看到更多代码很难说,但是我的猜测是,在调用setHeader之前,您已经将正文内容发送到浏览器。 Is that possible? 那可能吗? Setting the cookie must take place before anything else. 设置cookie必须先进行。

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

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