简体   繁体   English

当 twilio 收到短信时,我的代码返回 http 415 响应

[英]My code is returning a http 415 response when twilio receives an sms message

I've configured a webhook in Twilio to point to the below controller when someone sends an sms to my Twilio phone number.当有人向我的 Twilio 电话号码发送短信时,我在 Twilio 中配置了一个 webhook 以指向下面的 controller。 But, when an sms is sent, Twilio pops up a 11200 error and ngrok is telling me I'm returning an HTTP 415 error.但是,当发送短信时,Twilio 会弹出 11200 错误,ngrok 告诉我我正在返回 HTTP 415 错误。 Any ideas what I'm doing wrong?任何想法我做错了什么? Here is the controller:这是 controller:

    [HttpPost]
    public IActionResult Index(SmsRequest incomingMessage)
    {
        var messagingResponse = new MessagingResponse();
        messagingResponse.Message(_incomingSMSService.parseIncomingMessage(incomingMessage.From, incomingMessage.Body));

        return TwiML(messagingResponse);
    }

The SmsRequest is coming from the form data, so the controller should have [FormData]SmsRequest incomingMessage in it like this: SmsRequest 来自表单数据,因此 controller 应该有 [FormData]SmsRequest incomingMessage ,如下所示:

    [HttpPost]
    public IActionResult Index([FormData]SmsRequest incomingMessage)
    {
        var messagingResponse = new MessagingResponse();
        messagingResponse.Message(_incomingSMSService.parseIncomingMessage(incomingMessage.From, incomingMessage.Body));

        return TwiML(messagingResponse);
    }

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

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