没有 cookie 的 Node.JS 会话

发布于 2025-01-06 06:14:37 字数 169 浏览 0 评论 0原文

我一直在尝试,但我发现 iOS 5 默认情况下不接受 cookie。即使使用 Redis,我也尝试了很多不同的事情,但仍然无法让会话持续存在多个请求。

如果不使用 cookie,我还有哪些其他会话选项?我即将使用 Redis 推出一个粗略的会话模块,我只是来回发送我自己的“会话 ID”,但这似乎很容易制动。

I have been trying but I have found out that iOS 5 by default doesn't accept cookies. I have been trying many different things even using Redis but still cannot get a session to persist for more than one request.

Without using cookies, what other session options do I have? I am about to roll a crude session module using Redis where I just send my own "session id" to and from but that seems like it could easily brake.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半衬遮猫 2025-01-13 06:14:37

如果您无法让客户端支持 cookie,也许您可​​以将一些数据放入 LocalStorage,然后将其传递给服务器以连接到会话,并将其构造为单页应用程序。

它看起来像这样:

server                            |         client
send initial payload, with token  -->       store token in LocalStorage
initial payload contains some script

                                 <-- XHR request for /data?sessid=XXXXX
look up session, do stuff        -->  handle result, update DOM, do more XHR  

Are web sockets support?您可以使用 Socket.io 进行传输,这会大大减少延迟。

If you cannot get the client to support cookies, perhaps you can put some data into LocalStorage, and then communicate that up to the server to connect to the session, and structure it like a single-page app.

It'd look something like this:

server                            |         client
send initial payload, with token  -->       store token in LocalStorage
initial payload contains some script

                                 <-- XHR request for /data?sessid=XXXXX
look up session, do stuff        -->  handle result, update DOM, do more XHR  

Are web sockets supported? You could use Socket.io to do the transport, which would be a lot less latency.

烟燃烟灭 2025-01-13 06:14:37

我几乎可以肯定您会想要使用 cookie。另一种选择是通过 url 参数将会话 ID 附加到每个请求,并利用某种中间件将其保留在您的应用程序中,以确保其附加到每个 URL。您可以通过解析您的响应或劫持您的模板引擎以将其包含在每个链接和表单中来实现此目的。我觉得 iOS 没有 cookie 很奇怪。我几乎可以肯定这是不正确的,你能链接到你读到的地方吗?

I am almost sure you will want to use cookies. The other alternative would be to append a session id to every request via a url param and persist this across your app leveraging some kind of middleware to make sure its appended to every URL. You could do this by parsing your responses or by hijacking your template engine to include this in every link and form. I find it really strange the iOS doesn't havent cookies. I am almost sure that this is incorrect, can you please link where you read that?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文