I have the following javascript code, to produce a post request.
var postUrl = "http://localhost:3100/radiance";
xhttp.open("POST", postUrl, true);
xhttp.setRequestHeader('Content-type', 'application/json');
let radFile = {"radfile":"long string"}
let solarJson = {"key1":"value1","key2":"value2"}
let latitude = 45
let longitude = 24
msgJson=JSON.stringify({'radFile':radFile,'speedSolar':solarJson,'latitude':latitude,'longitude':longitude})
xhttp.send(msgJson);
The post request works absolutely fine with my express app code below.
var express = require('express');
// require our dependencies
var express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors');
var app = express();
var port = process.env.PORT || 3100;
var corsOptions = {
credentials: false
};
// use body parser
app.use(bodyParser.urlencoded({extended: true, limit: 1024 * 1024 * 10000, parameterLimit: 1000000*1000}));
app.use(bodyParser.json({type: 'application/json', extended: false, limit: 1024 * 1024 * 10000, parameterLimit: 1000000*1000}));
// route our app
var router = require('./app/routes');
app.use('/', router);
var server
// start the server
server = app.listen(port, function() {
console.log('app started ' +port );
});
However I am struggling to replicate the post request above in post man for testing (purposes).
I believe that the following post request should do the trick but when my app recieves this post request the body of the request is always empty. Why? It seems that the body parser isnt doing it's job.
What I am doing wrong in my post request in postman, how can I replicate my javascript post request exactly?