Twilio语音<Gather>-DotNetCore-Digits参数始终为null

问题描述

我正在尝试执行以下操作:

  1. 致电twilio#。
  2. 用户那里收集数字。
  3. 过程数字。

我正在使用DotNetCore webapi。

我遇到的问题是,当twilio发布到Gather action uri时,Digits始终为null。我在twilio调试控制台中确认Digits参数确实有一个值。

这是我的控制器的简化版本:

[ApiController]
[Route("api/[controller]")]
public class VoiceController : ControllerBase
{
    [HttpPost]
    public IActionResult Post()
    {
        var response = new VoiceResponse();
        var say = new Say("Please type your meeting password.");
        var gather = new Gather(action: "placeholderURI/JoinMeeting");

        response.Append(gather).Append(say);
        response.Redirect("placeholderURI");

        return Content(response.ToString(),"application/xml");
    }

    [HttpPost("JoinMeeting")]
    public IActionResult JoinMeeting(string Digits)
    {
        var response = new VoiceResponse();
        
        if(Digits != null){
            //do stuff
        }else{
            var say = new Say("WRONG");
            response.Append(say).Redirect("placeholderURI");
        }
        
        return Content(response.ToString(),"application/xml");
    }
}

此外,我可以将调试控制台中的RAW参数复制到邮递员的参数中,然后成功地发布到我的端点。

我错过了什么吗?也许对JoinMeeting方法有一些修饰?

解决方法

我没有阅读手册...

在twilio POST上,参数将在正文中。

在twilio GET上,参数将在查询字符串中。

我将第二种方法更新为GET并确保指定了该方法:

var gather = new Gather(action: "uriPlaceholder",method: HttpMethods.Get);