【发布时间】:2020-06-02 00:22:50
【问题描述】:
我正在尝试开始使用 Twilio 的可编程传真 API,并且我已经完成了他们的入门指南。但是,当我收到传真时,我会将请求正文记录到控制台。然而,身体只是一个空的对象。 我不确定出了什么问题。
const http = require('http');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
// Parse any incoming POST parameters
app.use(bodyParser.json({ extended: false }));
// Define a handler for when the fax is initially sent
app.post('/fax/sent', (req, res) => {
// Let's manually build some TwiML. We can choose to receive the
// fax with <Receive>, or reject with <Reject>.
console.log(req.body);
const twiml = `
<Response>
<Receive action="/fax/received" mediaType="application/pdf" storeMedia="true"/>
</Response>
`;
// Send Fax twiml response
res.type('text/xml');
res.send(twiml);
});
// Define a handler for when the fax is finished sending to us - if successful,
// We will have a URL to the contents of the fax at this point
app.post('/fax/received', (req, res) => {
// log the URL of the PDF received in the fax
console.log(req.body);
// Respond with empty 200/OK to Twilio
res.status(200);
res.send(req.body);
});
// Start the web server
http.createServer(app).listen(3000, () => {
console.log('Express server listening on port 3000');
});
这是我在控制台中返回的内容。您可以看到记录的空对象...
Express server listening on port 3000
{}
更新: 我将正文解析器中间件更改为使用 urlencoded app.use(bodyParser.urlencoded({extended: false })); 我得到了对象,但我没有看到媒体网址......
【问题讨论】:
标签: javascript node.js express twilio