I am facing an issue where the body of my Angular post request is empty on my server. The post request from my client application looks like this:
var data = {
Stime: '+this.Stime+',
Etime: '+this.Etime+',
eAMPM: '+this.eAMPM+',
sAMPM: '+this.sAMPM+',
id: '+this.id+',
activity: '+this.activity+',
auto_insert: '+this.auto_insert+',
yearmonthday: '+this.yearmonthday+',
color1: '+this.c+'
}
this.$http({
method: 'POST',
url: 'http://localhost:3000/operation',
data: JSON.stringify(data)
})
Prior to using this post request, I was sending a very long query string which worked perfectly fine for passing the data. However, now that I am cleaning up my code, this method is not working. On the server side, when I try to access the body of the post request, it shows as empty:
app.post('/operation', function(req,res){
console.log(req.body); //prints {}
res.send("inserted");
});
In addition, on the server side I have the following configurations:
var express = require('express'),
app = express(),
bodyParser = require('body-parser'),
cookieParser = require('cookie-parser'),
multer = require('multer'),
jsonParser = bodyParser.json()
app.use(jsonParser)
app.use(bodyParser.urlencoded({
extended: true
}))
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));