Node.js 如何在NodeJS中通过POST接收来自Mailgun的消息?
我正在尝试为从mailgun转发的消息设置API端点 在他们的文档中,有一个Django代码示例,如下所示:Node.js 如何在NodeJS中通过POST接收来自Mailgun的消息?,node.js,mailgun,Node.js,Mailgun,我正在尝试为从mailgun转发的消息设置API端点 在他们的文档中,有一个Django代码示例,如下所示: # Handler for HTTP POST to http://myhost.com/messages for the route defined above def on_incoming_message(request): if request.method == 'POST': sender = request.POST.get('sender
# Handler for HTTP POST to http://myhost.com/messages for the route defined above
def on_incoming_message(request):
if request.method == 'POST':
sender = request.POST.get('sender')
recipient = request.POST.get('recipient')
subject = request.POST.get('subject', '')
body_plain = request.POST.get('body-plain', '')
body_without_quotes = request.POST.get('stripped-text', '')
# note: other MIME headers are also posted here...
# attachments:
for key in request.FILES:
file = request.FILES[key]
# do something with the file
# Returned text is ignored but HTTP status code matters:
# Mailgun wants to see 2xx, otherwise it will make another attempt in 5 minutes
return HttpResponse('OK')
现在,在我的Express应用程序中,我得到了以下代码:
const express = require('express');
const router = express.Router();
// @route POST api/inbox
// @desc HTTP handler for messages from mailgun
// @access public
router.post('/',(req, res) => {
console.log("REQ PARAMS: ");
console.log(req.params);
console.log("REQ BODY: ");
console.log(req.body);
console.log("REQ JSON: ");
console.log(JSON.stringify(req.body));
const sender = req.body.sender;
const recipient = req.body.recipient;
console.log(sender);
console.log(recipient);
res.json({success: true});
});
module.exports = router;
这是部署在Heroku上的,当邮枪击中路线时,我得到以下输出:
2019-10-03T09:29:39.558514+00:00 app[web.1]: REQ PARAMS:
2019-10-03T09:29:39.558515+00:00 app[web.1]: {}
2019-10-03T09:29:39.558516+00:00 app[web.1]: REQ BODY:
2019-10-03T09:29:39.558518+00:00 app[web.1]: {}
2019-10-03T09:29:39.558519+00:00 app[web.1]: REQ JSON:
2019-10-03T09:29:39.558521+00:00 app[web.1]: {}
2019-10-03T09:29:39.558522+00:00 app[web.1]: undefined
2019-10-03T09:29:39.558524+00:00 app[web.1]: undefined
我不知道我做错了什么,所以我很高兴能得到任何帮助 问题是我使用的是
主体解析器
中间件,而不是
app.use(express.urlencoded())代码>
我的坏