javascript - 无法读取从 Express 服务器上的 React js 前端发送的 cookie
问题描述
在我的 React js 前端,我正在使用react-cookie 设置一个 cookie。我已验证请求 cookie 已正确设置:
在 Express 服务器上,我设置了cookie 解析器
app.use(cookieParser())
app.get('/instruments', function (req, res) {
// Cookies that have not been signed
console.log('Cookies: ', req.cookies)
// Cookies that have been signed
console.log('Signed Cookies: ', req.signedCookies)
})
正如我们所见,cookie 在服务器上是不可见的。为什么呢?
解决方案
您的代码工作正常
access-token=%7B%7D
url 解码为access-token={}
这是您的终端中记录的内容
似乎您react-cookie
用来发送 cookie 值的部分是问题而不是传输或服务器
推荐阅读
- json - 如何在不覆盖文件的情况下正确将此数据写入 JSON 文件?
- asp.net - 如何使用 Simple Injector 或 Microsoft.Extensions.Dependency 将视图依赖项注入 ASP.NET Web 窗体中的 Presenter (MVP)?
- javascript - 提交后仍会重定向 AJAX 调用的联系表单
- unity3d - 如何从 Animator 中检索当前正在播放的动画?
- wordpress - 如何在wordpress插件联系表7中验证当前服务器时间?
- python - 如何使用 matplotlib 绘制 0/1 的数组
- docker - 使用主机网络启动 Docker 容器,同时保持 SSH 进入容器的能力?
- python - 如何使用 cx freeze 使用 setup.py 构建 msi 扩展
- python - 在 Python 中的字典中查找两个值之间的路径
- neo4j - 在 Cypher Neo4j 中找到正确的路径