没有 cookie 的 Node.JS 会话
我一直在尝试,但我发现 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您无法让客户端支持 cookie,也许您可以将一些数据放入 LocalStorage,然后将其传递给服务器以连接到会话,并将其构造为单页应用程序。
它看起来像这样:
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:
Are web sockets supported? You could use Socket.io to do the transport, which would be a lot less latency.
我几乎可以肯定您会想要使用 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?