首页 > 解决方案 > 无法读取从 Express 服务器上的 React js 前端发送的 cookie

问题描述

在我的 React js 前端,我正在使用react-cookie 设置一个 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

正如我们所见,cookie 在服务器上是不可见的。为什么呢?

标签: javascriptnode.jsreactjstypescriptexpress

解决方案


您的代码工作正常

access-token=%7B%7Durl 解码为access-token={}

这是您的终端中记录的内容

似乎您react-cookie用来发送 cookie 值的部分是问题而不是传输或服务器


推荐阅读