i'm developing a node.js api for a simple app for the first time and i'm confused about receiving data on body.
The code:
router.route("/ReceiveJSON").get((request, response) => {
console.log(request.body);
response.send("ok");
});
I'm sending this on Postman to test:
{
"name": "test"
}
So i'm supposed to get this text on console, but i only get "{}" on console.
What am i doing wrong?
I dont know if this is causing the problem but i algo got the message "(node:11396) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated (Use node --trace-deprecation...
to show where the warning was created)" on console (but im not even using headers)
Hi you can try to use express like in this example:
const express = require('express')
const app = express()
app.use(
express.urlencoded({
extended: true
})
)
app.use(express.json())
app.post('/todos', (req, res) => {
console.log(req.body.todo)
})
I don't test it actually.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.