I'm posting some data from my ReactJS client to the Express server, but it seems that I cannot access the data in req.body.... I'm sending a JSON object this way:
var url = 'http://localhost:8000/scrape/';
const {main} = getState()
const info = { name : main.title, items : main.list}
var options = {
url: url,
method: 'POST',
body : JSON.stringify(info),
json: true,
headers : {
'Content-Type': 'application/x-www-form-urlencoded'
}
};
Request(options, (error, response, data) => {
// !error ? dispatch( setSearchResults(JSON.parse(data) ) ) : dispatch( setError(error) );
});
and when I console.log(req.body) in Express, I receive this:
{ '{"name":"test","items":': { '{"url":"test","code":"ING"},{"url":"test","code":"KIN"},{"url":"test","code":"GAO"}': '' } }
In my Express I use bodyParser
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
I tried using JSON.stringify(req.body) and JSON.parse(req.body) but both had not succes, any suggestions?