- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在express api引用中看到了数据
expressjs api reference for cookie
在文档中,cookie可以以JSON形式发送 res.cookie('cart', { items: [1,2,3] });
所以我开始尝试,当我使用字符串时,cookie 工作得很好,但不是 JSON 格式。
res.cookie('cookietmp',{test: ['test1', 'test2']}, { maxAge: 900000, httpOnly: true});
res.send('test cookie: ' + req.cookies.cookietmp)
这是我的代码
和我的浏览器显示
test cookie: [object Object]
我的浏览器似乎不知道格式是 JSON 之类的,我该如何解决它?
最佳答案
这是一个对象文字,不是 JSON。 JSON 是一种序列化格式,但您重新尝试设置为 cookie 值的不是字符串。您会在浏览器中看到 '[object Object]'
,因为这就是 Object.toString
返回。
您,程序员,需要使用 JSON.stringify
将该对象转换为 JSON :
var cookieValue = JSON.stringify({test: ['test1', 'test2']}, { maxAge: 900000, httpOnly: true});
res.cookie('cookietmp', cookieValue);
关于json - 通过json发送expressjs cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12241807/
基于此答案的问题:https://stackoverflow.com/a/18650183/4478897 我试图找到这个解决方案,但似乎没有任何效果符合我的需要。 集群 expressjs 和 so
我有一个使用 Sequelize.js 作为 ORM 运行的快速应用程序。我的 express 应用程序从我的主要 Rails 应用程序接收请求,并且由于跨域策略,这些请求是使用 getJSON 执行
如何处理同步错误并保证在同一代码中出现错误? 这是我的代码,但不确定其工作正常,有什么想法吗? helpers.list({ limit: 1 })
在我的 ExpressJS 代码中,我限制主体大小如下: app.use(bodyParser.urlencoded({ limit : "512kb", extended: fals
我有一个看起来像这样的对象: editinvite: { _id: '', title: '', codes_list: [] } 问题是我无法在 NodeJS 应用程序中访问codes_
我正在尝试让我的nodeapp 使用express 工作。 我已经通过 nginx 设置了反向代理以使用 https://dank.ml/api/v1但每当我启动我的应用程序时,它都不想检测 / 响应
我完全失去了理智: 我有一个快速应用程序:以下是此示例的几个文件的快照: 应用程序.js -模型 --Event.js --Match.js 路线 --matches.js app.js: globa
我有我的nodejs项目,我想将记录器与我的route.js分开以获得干净的代码。 但是我遇到了下一个问题,当我尝试将记录器加载到route.js 文件时,它会显示下一个错误: TypeError:
我在 MEAN 应用程序中的模板缓存方面遇到一些困难。我有一个导航栏,它使用条件逻辑来显示/隐藏向用户显示的按钮。当用户点击页面时,这些值将被设置为 null 或 false,但是一旦他们登录,这些值
是否可以根据可选路线创建不同的查询? app.get('/:genre/:book?', function (req, res) { var genre = req.params.genre; v
我正在尝试学习 ExpressJS,并且遇到了这段代码。我似乎无法理解 app.use 函数,并且文档对我来说也不清楚。当调用 app.use 时,此特定示例代码中的/public 目录到底发生了什么
我正在开发一个学校管理系统。当老师发送发布请求时,我在后端创建一个路由内的全局对象。所以当多个老师访问服务器时,会创建多个全局对象......或者每个老师访问同一个对象?(会被重写同一个对象吗?) 最
我有一个用 typescript 编写的小型微服务,在 AKS 上的 kubernetes 集群中运行。我使用 Helm 生成了入口 apiVersion: extensions/v1beta1 ki
我需要将 JSON 发送到我的服务器,但 POST 请求显示为空正文。这是我在前端的 typescript : function sendData() : void { console.log("Se
这是我的 app.js import path from 'path'; import bodyParser from 'body-parser'; import express from 'expr
我一直在使用 ExpressJS 来促进文件上传,但据我所知,您可以将文件上传到任何路由,无论它是否处理它。 说我有 app.post('/photos/upload', photos.upload)
我正在阅读 Express.JS 4.x API,并且很好奇他们是如何设置的。这是我对正在发生的事情的理解:在 Express.JS 4.x API 的示例代码中,express 模块被导入并分配给变
我有以下注册页面 form(method='post', action='users/register') .form-group label Name inp
我有诸如 :id/comments/、:id/otherRoute 等路线。对于这些路线,我需要创建新的 Controller 。例如: let id: number = +req.params["i
嘿,我有一个使用 Express.js 和 Handlebars 运行的网站,该网站的导航栏和侧边栏在所有页面上都保持相同。当我路由时,它仅更改页面容器 {{{body}}}。 有没有一种方法可以让我
我是一名优秀的程序员,十分优秀!