首页 > 解决方案 > 出现错误 - 可编程语音中的 twilio 中的 11200

问题描述

我在使用 Twilio 时遇到了间歇性问题。在每 50 次调用中,我们会接到一个失败的调用,当我检查日志时,它指出错误 11200,并给出“尝试从https://mednection.azurewebsites.net/appointment /fallback返回 HTTP 状态码 500"

我查看了 Twilio 关于此错误的建议(可在https://www.twilio.com/docs/errors/11200找到)。他们列出了一系列导致网关错误的可能原因:

1) Web 服务器向 Twilio 返回 4xx 或 5xx HTTP 响应 - 据我在日志中看到的,Web 服务器正在向 Twilio 返回 200 HTTP 响应。2) Web 服务器配置错误 - 我们已经检查了我们的 Web 服务器的配置,并且认为它是正确的。3) Twilio 和您的 Web 服务器之间的网络中断 - 我们已经测试了 ping 响应时间,以及 www.twilio.com 和我们的服务器之间的数据包丢失。ping 时间小于 15 秒,使用 ping -n 100 www.twilio.com 进行测试时似乎没有丢包 4) 响应中没有附加 Content-Type 标头 - 我们将 Content-Type 设置为 application/xml。5) Content-Type 与实际内容不匹配 - 我们将 Content-Type 设置为 application/xml 并使用 TwiML 语言发回我们的响应。

我们还检查了 Twilio 的可能解决方案部分中的所有元素是否存在此错误。

关于我们正在做的一些事情:

我们正在开发预约创建系统。在这两个电话中同时进行以检查双方的可用性,而挂断电话我遇到了这个问题。

我不排除这是导致问题的原因,但我们真的不知道接下来要检查什么。Web 服务器似乎正在发送 200 响应,但 Twilio 似乎正在接收 502。

有没有人有任何可以帮助我们的建议?会不会是我们使用的 API 有问题?

先感谢您!

暮光之城

标签: twilio

解决方案


Twilio seems to forget to set content-type for their requests... Which makes it impossible for a middleware to parse the body.

If you are using Node.js with express, here is a solution:

  • Check if there is no content-type set
  • If not, assume it's application/x-www-form-urlencoded which seems to be the actual content type Twilio is sending.
// This is used by your TwiML App as the Voice Request Url
app.post('/makecall', (req, res, next) => {
  if (!req.headers['content-type']) {
    req.headers['content-type'] = 'application/x-www-form-urlencoded'
    const urlEncodedMiddleware = bodyParser.urlencoded({ extended: false })
    urlEncodedMiddleware(req, res, next)
  } else {
    next()
  }
}, makeCall);

This solution is a bit future proof if Twilio decides to start sending content-type. But, it could break if they change the body format without sending the content-type...

Solution inspired by this answer: https://stackoverflow.com/a/17228529/1340601


推荐阅读