node中 不使用 中间件 直接 获取 req.body 值为 undefined
此时我们可以使用解析body的中间件body-parser
安装body-parser
在代码中加上下面的代码就可以了。
var bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
body-parser是一个HTTP请求体解析的中间件,使用这个模块可以解析JSON、Raw、文本、URL-encoded格式的请求体