Javascript Node.js POST请求返回为;{};
开始使用node.js并尝试使用带有fetch的POST请求,但是当我运行它时,它在控制台中返回为{} 服务器端代码--> 提取-->Javascript Node.js POST请求返回为;{};,javascript,node.js,Javascript,Node.js,开始使用node.js并尝试使用带有fetch的POST请求,但是当我运行它时,它在控制台中返回为{} 服务器端代码--> 提取--> 这是我写的,但我无法理解首先,您需要安装Node.js body解析中间件: $ npm install --save body-parser 然后: const bodyParser = require('body-parser'); app.use(bodyParser.json()); 此方法不返回任何内容,因此不知道为什么您会对此API不返回任何内
这是我写的,但我无法理解首先,您需要安装Node.js body解析中间件:
$ npm install --save body-parser
然后:
const bodyParser = require('body-parser');
app.use(bodyParser.json());
此方法不返回任何内容,因此不知道为什么您会对此API不返回任何内容感到惊讶。its
application/json“
console.log(请求)时会得到什么?在.post之后是否附加了其他中间件?您的post
api回调没有返回任何内容,您需要正文解析器他不需要正文解析器,他已经使用了expressexpress.json()中的内置正文解析器
他需要正文解析器,因为他记录了“request.body”,您为什么给我-1:-(
$ npm install --save body-parser
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.post("/api", (request,response) => {
console.log("Made the POST")
console.log(request.body)
})