app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: false}))
app.post('/user_create', (req,res) => {
console.log("trying to create a user "+req.body);
const firstName = req.body.first_name
const lastName = req.body.last_name
console.log("first name is "+firstName+" "+lastName);
res.end()
})
现在,在尝试了上面给出的所有文章之后,我仍然需要req.body未定义,我是Nodejs中的新手。我正在使用express 4.16.4和body-parser 1.18.3。
答案 0 :(得分:0)
let options = {
headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded'),
};