为 Twilio 响应格式化 XML

Formatting XML for Twilio Response

我正尝试在我的 Laravel 应用程序中接收传真,但我似乎无法正确设置 XML 的格式。

因为我是第一次设置它,所以我尝试模仿 Twilio 快速入门指南中的基本操作方法。

使用 Twilio 仪表板,我设置了 myapp 的 webhook 地址。com/fax/sent 在尝试发送传入传真时收到通知:

public function sent()
{
    $twimlResponse = new SimpleXMLElement("<Response></Response>");
    $recieveEl = $twimlResponse->addChild('Receive');
    $receiveEl->addAttribute('action', '/fax/received');

    return response($twimlResponse->asXML())
           ->header('Content-Type', 'text/xml');
}

我从 Twilio 得到的错误基本上是空的:

Error 12100 Document parse failure

Twilio 错误请求检查器没有显示头部或正文。

我也曾尝试 return 一个硬编码的视图文件来代替构建 xml:

查看fax.sent:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
   <Receive action="/fax/received" />
</Response>

然后将发送函数更改为:

public function sent()
   {
      return View::make('fax.sent')->header('Content-Type', 'text/xml');
   }

这 return 是相同的错误消息。

确保您的 twiML URL 可以从外部访问 Twilio(没有 firewall/IP 限制等)并且它是有效的 XML 并且具有正确的 Content-Type。