1)因為express將body-parser分離了出來,所以你需要手動添加進下面的內容即可
var path = require('path'); var bodyParser = require('body-parser');//用於req.body獲取值的 app.use(bodyParser.json()); // 創建 application/x-www-form-urlencoded 編碼解析 app.use(bodyParser.urlencoded({ extended: false }));
2)如果你傳輸的內容不是string類型時,你需要對上面的配置進行修改:
app.use(bodyParser.urlencoded({ extended: true}));
否則也總是會得到undefined的結果