简体   繁体   English

从响应中获取 set-cookie 值 header angular

[英]Get set-cookie value from the response header angular

I am trying to get the set-cookie from Response Headers .我正在尝试从Response Headers获取set-cookie

The reason of doing this is set-cookie is not setting cookie and showing the warning This attempt to set a cookie via a Set-Cookie header was blocked because its Domain attribute was invalid with regards to the current host url .这样做的原因是 set-cookie 没有设置 cookie 并显示警告This attempt to set a cookie via a Set-Cookie header was blocked because its Domain attribute was invalid with regards to the current host url . Attached is the screenshot附上截图

在此处输入图像描述

Now I thought to get the set-cookie value from Response Header by the following code现在我想通过以下代码从 Response Header 中获取 set-cookie 值在此处输入图像描述

But it always returns null for set-cookie but return the value fo expires .但它总是为set-cookie返回null但返回值 fo expires

Please anyone can guide how to fix this issue or how can I get the value of set-cookie from Response Header.请任何人指导如何解决此问题或如何从响应 Header 中获取set-cookie的值。

Any help will be highly appreciated.任何帮助将不胜感激。

Thanks谢谢

According to developer.mozilla.org set-cookie is a forbidden response header name.根据developer.mozilla.org set-cookie是禁止响应 header 名称。 You cannot read it using browser-side JavaScript您无法使用浏览器端 JavaScript 读取它

Browsers block frontend JavaScript code from accessing the Set Cookie header, as required by the Fetch spec, which defines Set-Cookie as a forbidden response-header name that must be filtered out from any response exposed to frontend code.根据 Fetch 规范的要求,浏览器阻止前端 JavaScript 代码访问 Set Cookie header,该规范将 Set-Cookie 定义为禁止的响应标头名称,必须从任何暴露给前端代码的响应中过滤掉。

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

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