Express 无法从axios获取正文。删除服务器端
我无法访问使用axios.delete()函数发送的数据,无法在后端执行操作 这是我的axios呼叫:Express 无法从axios获取正文。删除服务器端,express,axios,Express,Axios,我无法访问使用axios.delete()函数发送的数据,无法在后端执行操作 这是我的axios呼叫: export const deleteBooking = (email, bookingObjId) => { console.log("Parameters are both strings and received properly" , email, bookingObjId) const response = axios.delete(`/users`
export const deleteBooking = (email, bookingObjId) => {
console.log("Parameters are both strings and received properly"
, email, bookingObjId)
const response = axios.delete(`/users`,
{data: {userId: email, bookingId: bookingObjId}})
return response
}
这是我接收它的代码:
bookingRouter.delete('/', async(req, res) => {
body = req.body
console.log("body receives nothing, it's just {}", body)
var id = mongoose.Types.ObjectId(body.bookingId)
const deleted = await User.updateOne({email: body.userId},
{$pull: {'bookings': {'_id':id}}}, {safe: true, multi: true})
res.status(200).json(deleted)
})
我也尝试过req.params,但不起作用。这似乎是一个简单的解决办法,但我找了几个小时后找不到它。我知道这与猫鼬或react没有任何关系,但这不可能。这是我在搜索数小时后发布的解决方案:
const response = axios.request({
method: 'delete',
url,
data
})
工程,根据: