ExpressJS Unicode Cookie [英] ExpressJS unicode cookie

查看:40
本文介绍了ExpressJS Unicode Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以在expressjs中的cookie中发送unicode值.当用户使用西班牙语语言环境时,cookie会使用用户名序列化,该用户名可以是José"之类的

Is there any way to send unicode values in a cookie in expressjs. When a user is using a Spanish locale, a cookie is serialized with the user name, which can be something like "José"

例如:

 res.cookie('user', JSON.stringify({name: 'José'}));

但是在客户端中,我会得到一个cookie,其值为:

However in the client I get a cookie with the value:

{name: 'José'}

有什么解决办法吗?服务器已经输出了.

is there any way around this? The server already outputs that.

推荐答案

要在cookie中使用unicode字符,您应该使用一种编码方案.

To be able to use unicode characters in a cookie, you should use an encoding scheme.

encodeURIComponent()或querystring.escape()应该起作用.

encodeURIComponent() or querystring.escape() in node when setting the cookie and decodeURIComponent() in the client should work.

表达并不是特定的,而是cookie的一般工作方式.有关详细信息,请参见以下答案: Cookie中允许使用的字符

It's not specific to express, but how cookies work in general. See this answer for details: Allowed characters in cookies

这篇关于ExpressJS Unicode Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆