body express 中间件里面是空的
body inside express middleware is empty
我正在接收来自 mailgun 的电子邮件,所以我将端点设置如下
app.post(
'http://www.example.com/mail',
async(req, res, next) => {
// i want to check if email coming from mailgun
// so i want to set if statement using the req.body['X-Mailgun-Coming']
// which should be Yes
// but i got empty body object
},
uploadHandler.any(),
comingEmails // but body in this function has the required data
)
如你所见,我在中间件中得到了空 body 但在主要功能中,body 具有所需的并且我可以访问此数据
注意 ==> 只有当电子邮件有附件时才会发生这种情况
uploadHandler.any()
必须在您检查 req.body
之前,因为它是实际读取请求正文并填充 req.body
的中间件。因此,您正在尝试在实际将值放入其中的代码运行之前读取 req.body
。
在尝试使用 req.body.
之前,您应该这样写
app.post(
'http://www.example.com/mail',
uploadHandler.any(),
async(req, res, next) => {
// i want to check if email coming from mailgun
// so i want to set if statement using the req.body['X-Mailgun-Coming']
// which should be Yes
next();
},
comingEmails
);
我正在接收来自 mailgun 的电子邮件,所以我将端点设置如下
app.post(
'http://www.example.com/mail',
async(req, res, next) => {
// i want to check if email coming from mailgun
// so i want to set if statement using the req.body['X-Mailgun-Coming']
// which should be Yes
// but i got empty body object
},
uploadHandler.any(),
comingEmails // but body in this function has the required data
)
如你所见,我在中间件中得到了空 body 但在主要功能中,body 具有所需的并且我可以访问此数据
注意 ==> 只有当电子邮件有附件时才会发生这种情况
uploadHandler.any()
必须在您检查 req.body
之前,因为它是实际读取请求正文并填充 req.body
的中间件。因此,您正在尝试在实际将值放入其中的代码运行之前读取 req.body
。
在尝试使用 req.body.
之前,您应该这样写app.post(
'http://www.example.com/mail',
uploadHandler.any(),
async(req, res, next) => {
// i want to check if email coming from mailgun
// so i want to set if statement using the req.body['X-Mailgun-Coming']
// which should be Yes
next();
},
comingEmails
);