Nodejs没有收到POST正文

我在angularjs中发送一个POST,如下所示:

$http.post("/mypath", { data: "foobar" }) 

而在nodejs(expressjs)我试图把它拿起来,像这样:

 app.post "/mypath", (req, res) -> console.log "req.body: ", req.body res.end() 

我尝试了各种不同的化身( body: "foobar"等),但我一直得到req.body: undefined

有没有简单的方法来读取节点/快递中的有效载荷?

要从节点中的POST获取数据,您需要使用正文parsing器。 例如:

 var bodyParser = require('body-parser'); //use bodyParser() to let us get the data from a POST app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json());