我试着用Fetch()
API来发布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)
})
这是处理请求的路由
router.post('/test',(req,res)=>{
console.log(req.body)
res.send('OK')
})
然而,console.log(req.body)
的输出是{}
.
我想问题出在body:
之后的代码,我不知道发布文本/纯数据的正确方式是什么.