【问题标题】:Twilio 11200 HTTP retrieval failure with Node app on HerokuHeroku 上的 Node 应用程序的 Twilio 11200 HTTP 检索失败
【发布时间】:2017-11-16 17:24:37
【问题描述】:

我的 Node.js 应用程序设置为响应通过付费 Twilio 号码收到的短信。我使用 ngrok 对其进行了测试,一切正常。但是,将应用程序部署到 Heroku 后,我开始在 Twilio 控制台中看到 11200 HTTP 检索失败错误。

我需要在 Heroku 中设置配置设置吗?

// Twilio Credentials
const accountSid = 'xxx';
const authToken = 'xxx';
const client = require('twilio')(accountSid, authToken);
const MessagingResponse = require('twilio').twiml.MessagingResponse;

var express = require('express');
var app = express();   
var bodyparser = require('body-parser');

app.use(bodyparser.urlencoded({extended: true}));

app.set('port', (process.env.PORT || 3000));

app.use('/', function(request, response){
response.send();
});

app.post('/sms', function(req, res) {

const twiml = new MessagingResponse();

twiml.message('Hi, this is Culpability. Your incident has been logged. Your 
unique id # XXXX');

res.writeHead(200, {'Content-Type': 'text/xml'});
res.end(twiml.toString());

});

app.listen(app.get('port'), function() {
// console.log('Node app is running on port', app.get('port'));
});

【问题讨论】:

  • 您是否将手机的 URL 更新为 Heroku URL?例如,您是否测试过可以使用curl 访问 Heroku URL?
  • 检查了 URL 并将尝试 curl 但我已验证 Heroku URL 可以通过其他方式访问!
  • 您能否通过电子邮件与我分享您的应用程序的 URL,我会看看我能找到什么?电子邮件地址是 philnash@twilio.com
  • 是的,现在发送。感谢您的帮助。

标签: node.js heroku twilio


【解决方案1】:

这里是 Twilio 开发者宣传员。

我认为问题主要在于您用于发送响应的方法。目前/sms 路线的最后一行是res.end(twiml.toString()); 但是Response#end is used "to quickly end the response without any data."

我认为您对res.writeHead() 的使用现在也可能已经过时了。

我会将您的 /sms 路由更改为这样的:

app.post('/sms', function(req, res) {
  const twiml = new MessagingResponse();
  twiml.message('Hi, this is Culpability. Your incident has been logged. Your unique id # XXXX');
  res.set('Content-Type', 'text/xml');
  res.status(200).send(twiml.toString());
});

然后尝试重新部署到 Heroku,看看会发生什么。

【讨论】:

    猜你喜欢
    • 2016-09-21
    • 2020-11-08
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多