我看到服务器端的cookie出现了一些奇怪的行为,我想知道为什么。
在客户端:
document.cookie = 'test_cookie=' + '[AB]cd|ef-gh[IJ]' + '; path=/;';
document.cookie = 'test_cookie2=' + 'cd|ef-gh' + '; path=/;'; 在服务器上:
headers = httpServletRequest.getHeaders()
// iterate and print headers
cookies = httpServletRequest.getCookies();
// iterate and print headers输出:
// Both are there on the header, so tomcat doesn't block it:
...
header: cookie: test_cookie=[AB]cd|ef-gh[IJ]; test_cookie2=cd|ef-gh
// Only one shows up from getCookies()
...
cookie: test_cookie2=cd|ef-gh
// no test_cookie ???为什么我看不到test_cookie2?我可以在客户端设置之前进行uri编码,但我认为'‘和'’是允许的cookie字符?
有没有更正确的设置方法?
发布于 2017-10-12 04:19:02
下面是在前端正确设置cookie的方法:
document.cookie = 'test_cookie="[AB]cd|ef-gh[IJ]"; path=/';而不是包含特殊字符的Cookie值两边的双引号。
https://stackoverflow.com/questions/46695909
复制相似问题