get请求的参数可以通过req.query获取
app.get('/login', (req, res) => {
/* 通过req.query获取get请求时url的参数, 获取的是key-value...})
而post请求, 在express中没有内置获取post请求参数的api, 需要使用第三方模块body-parser作为中间件进行注册.
body-parser文档
安装
npm install...false }))
app.use(bodyParser.json())
app.post('/login', (req, res) = > {
/* 通过req.body获取post请求的参数...secure: true }
}))
使用
// 设置cookie, maxAge为过期时间, 以ms为单位
res.cookie('username', 'caicai', { maxAge: 7...* 24 * 3600 * 1000, httpOnly: true});
// 获取cookie
res.cookies.username
// 删除cookie
res.clearCookie(