问题描述
我遇到了一个奇怪的问题.我正在构建一个与 Drupal 服务交互的外部移动 web 应用程序.当我调用 login.json 服务时,会设置一个 cookie(或者我认为是这样),它告诉 Drupal 我已登录.
I'm running into a weird problem. I'm building an external mobile webapp that intefaces with Drupal Services. When I call the login.json service, a cookie is set (or so I think) that tells Drupal that I'm logged in.
Web 应用程序当前在同一个域下运行,但在一个子目录中.但这里是棘手的部分.在我的 chrome 资源浏览器中,我可以看到 cookie 下的 cookie.但是,当我尝试记录 document.cookie 的内容时,它返回空.
The webapp is currently running under the same domain but in a subdirectory. But here's the tricky part. In my chrome resources browser, I can see the cookie under cookies. However, when I try to log the contents of document.cookie it comes back empty.
我需要做的是在我的 JS 代码中检查该 cookie 是否存在.但由于我无法从 document.cookie 获取它,我不确定我错过了什么.
What I need to do is check for that cookie's existence in my JS code. But since I can't get it from document.cookie, I'm not sure what I'm missing.
此外,cookie 的到期日期不早于今天,并且域匹配.
Also, the cookie's expiration date is not earlier than today, and the domain matches.
预先感谢您的帮助!
推荐答案
听起来 cookie 是 HTTP只有.如果这是由 Drupal 设置的,如果没有可用设置,您可能需要修改 Drupal 源代码来更改它.
Sounds like the cookie is HTTP only. If this is set by Drupal, you may have to modify the Drupal source code to change it if there is no setting available.
Drupal 跟踪器上的票表明从 v6.x 开始仅使用 HTTP cookie,如一种安全措施.
A ticket on the Drupal tracker indicates that HTTP only cookies are used starting from v6.x, as a security measure.
这篇关于无法在 JS 中使用 document.cookie 访问 cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!