SendGrid事件Webhook ASP.NET MVC Post为null

时间:2017-09-19 21:56:04

标签: c# asp.net-mvc sendgrid

我希望有人可以提供帮助。我有一个通过Azure运行的ASP.NET MVC网站。这里的最终目标是将SendGrid事件记录到数据库中。首先,我需要获取SendGrid发送的JSON。我已在Settings--> Mail Settings--> Event Notification下启用了“事件通知”。在Azure和Azure远程调试中使用Postman和Streaming Log,我确定我的控制器确实从SendGrid接收POST请求,但是我没有得到任何JSON。

我尝试过以下方法:

在下面的示例中,json为null:

public ActionResult SendGridOne(string json)

在下面的示例中,eventList为null(注意这是使用Sendgrid.Webhooks nuget包):

public ActionResult SendGridOne([FromBody]SendGridEvents[] eventList)

还试过以下内容,但rawSendGridJSON始终为null:

public ActionResult SendGridOne()
        {

            System.IO.StreamReader reader = new System.IO.StreamReader(HttpContext.Request.InputStream);
            string rawSendGridJSON = reader.ReadToEnd();
            System.Diagnostics.Trace.TraceInformation(rawSendGridJSON);
            return new HttpStatusCodeResult(200);
        }

1 个答案:

答案 0 :(得分:0)

Sendgrid.Webhooks nuget软件包正确。我用这种形式测试,它可以正常工作:

mlbench

在Github上访问Sendgrid Webhooks