admin管理员组文章数量:1339483
On Google Chrome, when I look at the HTTP request headers under the "Network" tab using the chrome console, it provides me the following request headers:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:ASP.NET_SessionId=nlbupfbt32jda1tziep4p21r; .ASPXAUTH=8C94786DD4A3C03C5548973E04A76FF554F38D6EB74E0B006AB3C3F72684E94DC0469E28D22E4BBFA069B82B1CCFB4203627D998990C6C96897DDBB0F611809175D5F06F015604082481F0079AE48DAB7974F3D63242055BEC75F707C545666C67B7C9D9E53F7531020235881E9DA4F3C26FD02B0ED0971D02C64DFE96F67C745119F44BBC9E46DC2CEF61D639EA01B9
... more headers ...
What I am trying to get is the data under Cookie. I have tried document.cookie
but it returns an empty string. How can I grab that cookie information?
On Google Chrome, when I look at the HTTP request headers under the "Network" tab using the chrome console, it provides me the following request headers:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:ASP.NET_SessionId=nlbupfbt32jda1tziep4p21r; .ASPXAUTH=8C94786DD4A3C03C5548973E04A76FF554F38D6EB74E0B006AB3C3F72684E94DC0469E28D22E4BBFA069B82B1CCFB4203627D998990C6C96897DDBB0F611809175D5F06F015604082481F0079AE48DAB7974F3D63242055BEC75F707C545666C67B7C9D9E53F7531020235881E9DA4F3C26FD02B0ED0971D02C64DFE96F67C745119F44BBC9E46DC2CEF61D639EA01B9
... more headers ...
What I am trying to get is the data under Cookie. I have tried document.cookie
but it returns an empty string. How can I grab that cookie information?
2 Answers
Reset to default 8Edit: document.cookies -> document.cookie
document.cookie
returns nothing because the cookie is almost certainly marked with the HttpOnly attribute.
The presence of this attribute tells the browser to disallow access to the cookie value via document.cookie
.
This is a security measure to prevent against session hijacking via cross-site scripting mostly.
If the cookie was set with the http-only flag, you can't read it using JavaScript - this is a security measure to prevent session hijacking and should be set for any surrogate identifier including session cookies.
本文标签: javascriptGet the cookie from an HTTP request headerStack Overflow
版权声明:本文标题:javascript - Get the cookie from an HTTP request header - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743583160a2506030.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论