【发布时间】:2019-03-04 19:02:20
【问题描述】:
我正在尝试通过 axios 请求将数据发送到我的后端脚本,但正文看起来是空的。
这是前端发送的请求:
axios.request({
method: 'GET',
url: `http://localhost:4444/next/api`,
headers: {
'Authorization': token
},
data: {
next_swastik: 'lets add something here'
},
}).then((res)=>{
console.log("api call sucessfull",res);
}).catch((err)=>{
console.log("api call unsucessfull",err);
this.props.toggleLoading(false);
})
这是一个后端:
app.get('/next/api', verifyToken, function(req, res) {
console.log(req.body);
})
但是我得到了{} 空的身体。我得到的是标题和其他数据,但不是数据。
【问题讨论】:
-
如果您确定您是通过 POST 发出请求,那么您的问题可能是 bodyParser。请确保您的 express 实例正在使用它。
标签: javascript node.js reactjs axios