我無法檢索從客戶端發送到服務器的資料。
我的反應代碼如下:
axios.post('http://localhost:5000/post-entry', { data: formData })
.then(res => {
console.log(res);
})
我的服務器代碼如下:
app.post('/post-entry', (req, res) => {
console.log(req.data, "res.body.data here");
});
當它到達我服務器上的帖子時,日志是undefined.
我究竟做錯了什么?
uj5u.com熱心網友回復:
如果formData是 JS 物件,就axios.post('http://localhost:5000/post-entry', formData)足夠了。您可以在服務器端通過req.body. 但是 ExpressJS 需要一個中間件來決議請求體。您必須使用app.use(express.json())or app.use(bodyParser.json())where bodyParser is body-parser。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/475476.html
