当我在前端执行请求时,我有一个有效的对象文件,其中包含数据。但是当我在express后端接收到body时,file对象是空的。
let body = {
metadata: {
date: date,
location: location,
description: description,
file: file
}
}
const headers = {'body': JSON.stringify(body)}
axios.get('/api/xummMint', {headers}).then( (res) => {
console.log("xumm data coming");
console.log(res)
setData({xummData: res});
})
当我console.log(req.headers.body)时,我收到一个空文件对象,即使文件在前端有数据:
{"metadata":{"date":"2022-12-30","location":"asf","description":"asdf","file":{}}}
我尝试使用fetch和添加content-Type: application/json,但结果仍然相同。有人能帮忙吗?
很可能您打算将此作为带有JSON正文的POST请求发送,而不是作为带有标题名为"body">
的GET请求发送。axios.post(
'/api/xummMint',
body,
{headers: {'Content-Type': 'application/json'}}
).then(res => {
console.log("xumm data coming");
console.log(res);
setData({xummData: res});
});