我有一个在前台发起的帖子请求:
const response = await fetch("http://localhost:5000/createUser", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: user.email,
}),
});
在我的Express/Node后端,我只记录请求正文:
app.post('/createUser', async (req, res) => {
try {
console.log('Request body:', req.body);
} catch (error) {
console.error('Error creating user:', error);
}
});
但是,这是记录到控制台的内容:
Request body: undefined
我不确定为什么会发生这种情况.我收到的请求工作得很好,这是我唯一在做的帖子.有人知道我怎么解决这个问题吗?