简体   繁体   English

未在浏览器中设置响应头中的Set-Cookie

[英]Set-Cookie in Response Header not being set in browser

I am having issues with trying to set a cookie from a Response Header, I can see the set-cookie key with all the options that i have specified but for some reason it is not being set in the browser (Chrome). 我在尝试从响应标头设置cookie时遇到问题,我可以看到set-cookie键以及我指定的所有选项,但是由于某种原因,它没有在浏览器(Chrome)中设置。

I am setting the cookie using koajs, and reads as follows: 我正在使用koajs设置cookie,内容如下:

this.cookies.set(’test-cookie’, ‘valid’, { domain: ‘.test.io’, httpOnly: false, maxAge: 604800000 })

this is what I get in the response: 这是我得到的回应:

GET https://api.test.io/conversion

set-cookie: test-cookie=valid; path=/; expires=Mon, 12 Jun 2017 14:23:40 GMT; domain=.test.io;

I have another request (GET https://identity.test.io/identity ) that does a similar request and has the same set-cookie response and i can see this cookie in chrome dev tools. 我有另一个请求(GET https://identity.test.io/identity ),该请求执行类似的请求并具有相同的set-cookie响应,我可以在chrome开发工具中看到此cookie。

The only difference is api.test.io goes through several redirects (301), however we do not think that is the issue as we still see the set-cookie key in the final response header. 唯一的区别是api.test.io经历了几次重定向(301),但是我们认为这不是问题,因为我们仍然在最终响应标头中看到set-cookie键。

nb: this cookie needs to work across multiple sites which is why we don't set secure, signed or httpOnly. nb:此cookie需要在多个站点上工作,这就是为什么我们不设置安全,签名或httpOnly的原因。

My answer is strictly for local testing, but I am putting it here as an answer cause your question is exactly what I searched for before I fixed it. 我的答案严格来说是针对本地测试,但我将其放在此处作为答案,因为您的问题恰好是我在修复它之前所寻找的。

My php.ini file had the session.auto_start setting set to 0. I set it to 1, and the browser started saving cookies that were in response header. 我的php.ini文件的session.auto_start设置设置为0。我将其设置为1,浏览器开始保存响应头中的cookie。 (using WAMP with PHP 7.0.29) (将WAMP与PHP 7.0.29结合使用)

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

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