reactjs - Node.js React node-fetch empty body post -
i trying simple post reactjs node.js server using node-fetch; however, body of request empty (i have not been able come configuration results in non-empty body). have read seemingly every stackoverflow question , none solves predicament, sadly. here reactjs code:
fetch('http://localhost:3000/sayhello/', {headers: new headers({ 'content-type': 'application/json' }), method: 'post', body: {"nose":"bop"} }) .then(function(res) { return res.json(); }).then(function(json) { console.log(json); }); and server.js: ... import bodyparser 'body-parser';
app.use(bodyparser.urlencoded({extended : true})); app.use(bodyparser.json()); app.post('/sayhello/', function(req, res) { console.log(req.body); res.send(req.body); }); the console gives empty body, , response undefined. happens when rather json post string body. ideas?
thanks
not worry friends seems have figured out. missing json.stringify in body. hope helps sometime, avoid pulling out hair did :)
Comments
Post a Comment