I have this code in my node backend server:
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
And this is the api i.e. i want to call:
router.post('/update/:_id', function(req, res, next) {
console.log("req.body:" + req.body);
}
This is my post request through angular 1:
var data = {something: "something"}
var url = 'http://localhost:8081/update/5982168b399ccf32ad75ce2e';
$http({
withCredentials: false,
method: 'POST',
url: url,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: data
})
.then(function (response) {
if (response.data) {
console.log("Post Data Submitted Successfully!");
}
}, function (response) {
console.log("Error status: " + response.status)
});
I am using Angular 1.6.1 version.
I have tried everything and looked through countless posts but none helped me. I can see the body going through. But i got undefined req.body in the node side backend.
Any help would be appreciated.
Thanks.
app.useand routes).