简体   繁体   English

Twilio XML对SMS的响应

[英]Twilio XML response to SMS

I am trying to complete a sample SMS app with Twilio where I send a SMS message to my Twilio number and the Twilio service sends me back a reply. 我正在尝试使用Twilio完成一个示例SMS应用程序,在该应用程序中,我会向我的Twilio号码发送一条SMS消息,然后Twilio服务会向我发送回信。 I know the Twilio service is reaching my API because I can see the incoming request from Twilio reaching my API and I can see the response of my API, but I think somethng is wrong, as I never get an SMS response back. 我知道Twilio服务正在到达我的API,因为我可以看到来自Twilio的传入请求到达我的API,并且可以看到我的API的响应,但是我认为有些错误,因为我从未收到过SMS响应。

[HttpPost]
[Route("EchoTest")]
public IHttpActionResult EchoTest()
{
    string response = "<Response><Sms>Thanks for the message</Sms></Response>";
    return ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, response, new XmlMediaTypeFormatter()));
}

I am returning the ResponseMessage so I can be consistent in returning an IHttpActionResult . 我正在返回ResponseMessage所以我可以一致地返回IHttpActionResult I have also tried returning just HttpResponseMessage as seen below with the same results. 我也尝试过只返回HttpResponseMessage ,如下所示,结果相同。

[HttpPost]
[Route("EchoTest")]
public HttpResponseMessage EchoTest()
{
    string response = "<Response><Sms>Thanks for the message</Sms></Response>";
    Request.CreateResponse(HttpStatusCode.OK, response, new XmlMediaTypeFormatter());
}

This is what my API is sending back ... 这就是我的API回发的信息...

<string
 xmlns="http://schemas.microsoft.com/2003/10/Serialization/">&lt;Response&gt;&lt;Sms&gt;Thanks for the message&lt;/Sms&gt;&lt;/Response&gt;
</string>

Am I messing up the XML response? 我搞砸了XML响应吗? What I am looking to send back to Twilio is this ... 我希望发回Twilio的是这个...

<Response><Sms>Thanks for the message</Sms></Response>

See webpage : https://msdn.microsoft.com/en-us/library/hh969056(v=vs.118).aspx Try this 参见网页: https : //msdn.microsoft.com/zh-cn/library/hh969056(v= vs.118) .aspx尝试一下

XElement response = XElement.Parse("<Response><Sms>Thanks for the message</Sms></Response>");
    Request.CreateResponse<XElement>(request, HttpStatusCode.OK, response);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM