简体   繁体   English

如何使用c#webforms在twilio中接收传入的短信?

[英]How to receive incoming sms in twilio using c# webforms?

I am using Twilio API to send and receive SMS in c#. 我正在使用Twilio API在c#中发送和接收短信。 I have implemented send SMS successfully. 我已成功实施发送短信。 The problem is in receiving SMS. 问题在于接收短信。 Twilio documentation only shows MVC code to receive SMS. Twilio文档仅显示接收SMS的MVC代码。 Is it possible to receive SMS in asp.net web forms? 是否可以在asp.net网络表单中接收短信? Here is the documentation to receive SMS. 这是接收SMS的文档。 Receive SMS in twilio 在twilio接收短信

My project is in asp.net web form. 我的项目是asp.net网络表单。 Do I need to switch to the MVC? 我需要切换到MVC吗?

Twilio evangelist here. Twilio福音传教士在这里。

If you're using WebForms, I generally recommend receiving SMS messages using a Generic HTTP Handler. 如果您使用的是WebForms,我通常建议您使用Generic HTTP Handler接收SMS消息。 Twilio passes parameters like the message body as form encoded params, so its easy to grab those from the request context. Twilio将消息体之类的参数传递为表单编码参数,因此很容易从请求上下文中获取这些参数。

public class Twiml : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "application/xml";

        var Body = context.Request.Forms["Body"];

        var response = new Twilio.TwiML.MessageResponse();
        response.Message("You said: " + Body);

        context.Response.Write(response.ToString());
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

Hope that helps. 希望有所帮助。

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

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