我想使用组件文件中的Http.put请求将一些数据(以JSON格式)从前端(Angular 7)发送到后端(NodeJS)。在主控制台中,我以未定义的格式获取数据。下面是我的前端和后端代码。
this.http.put('/api/home', {moo:"foo",goo:"loo"}).subscribe(ccc => {
console.log("Status:" + ccc);
this.b = ccc;
})
router.put("/home", function (req, res) {
var aaa = req.body;
console.log(aaa);
res.send(cc)
});在后端,我在甲骨文公司(console.log)没有明确的定义。我想要foo或者loo。
发布于 2019-07-21 14:55:46
你必须先使用正文解析器,然后再使用路由器。
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: false })); // support encoded bodies
app.use('/', router);https://stackoverflow.com/questions/57129538
复制相似问题