英文:
Why are the cookies are being sent with every request but not visible in browser console or with document.cookie?
问题
我有一个非常奇怪的问题,我在我的Angular 7项目中使用express服务器在浏览器中设置cookie,然后API调用后应该发送带有cookie的请求。响应头显示cookie已经设置,后续API调用的请求头显示cookie已经被发送。但问题是,cookie在浏览器开发者控制台或document.cookie的输出中不可见。下面附上了设置cookie的响应头的截图:
在进行进一步的API调用时,以下是附加的请求头:
这个问题未解决该问题,因为HttpOnly cookie只有1个,即使是HttpOnly cookie也应该在浏览器开发者控制台上显示。
英文:
I have a very strange problem, I am using an express server to set cookies in my Angular 7 project in the browser and later API calls are supposed to send cookies with them. The response header shows that the cookie is being set and request headers of later API calls show that the cookies are being sent. But the problem is the cookies are not visible in the Browser Developer console or as the output of document.cookie. Below attached is the screenshot of response header for setting cookies:
Below is the request header attached while making further API calls:
This question does not resolve the issue as HttpOnly cookie is only 1 out of 3 and even the HttpOnly cookies should be displayed on the browser developer console.
答案1
得分: 4
The cookie's domain should match the domain of the UI app to be seen in developer tools. If the cookie is dropped in api.domain.com
and app is in ui.domain.com
then via developer tools you can only see cookies in ui.domain.com
. You can try explicitly setting the cookie domain to domain.com
to see them in dev tools.
英文:
The cookie's domain should match the domain of the UI app to be seen in developer tools. If the cookie is dropped in api.domain.com
and app is in ui.domain.com
then via developer tools you can only see cookies in ui.domain.com
. You can try explicitly setting the cookie domain to domain.com
to see them in dev tools
答案2
得分: 0
此外,您可以使用通配符为 domain
属性设置您的 cookie,例如:.domain.com
。
英文:
In addition, you can set your cookie with a wildcard for the domain
property, eg: .domain.com
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论