Heim > Fragen und Antworten > Hauptteil
高洛峰2017-04-17 16:27:37
express解析body需要用到body-parser中间件
var express = require('express')
var bodyParser = require('body-parser')
var app = express()
var jsonParser = bodyParser.json()
var urlencodedParser = bodyParser.urlencoded({ extended: false })
app.post('/login', urlencodedParser, function (req, res) {
if (!req.body) return res.sendStatus(400)
res.send('welcome, ' + req.body.username)
})
soonfy