I try to use Fetch() API to post text/plain
fetch('/test', {
method: 'post',
headers: {
'Content-Type': 'text/plain'
},
body: "this is a test"
})
.then(response => response.text())
.then(body => {
console.log(body)
})
This is the router that deal with the request
router.post('/test',(req,res)=>{
console.log(req.body)
res.send('OK')
})
However, the output of console.log(req.body)
is {}
.
I think the problem is the code after body:
. I don’t know what is the right way to post text/plain data.