【发布时间】:2017-09-19 21:56:03
【问题描述】:
我希望有人可以提供帮助。我有一个通过 Azure 运行的 ASP.NET MVC 网站。这里的最终目标是将 SendGrid 事件记录到数据库中。首先,我需要获取 SendGrid 发送的 JSON。我在Settings--> Mail Settings--> Event Notification 下打开了事件通知。在 Azure 和 Azure 远程调试中使用 Postman 和 Streaming Logs,我确定我的控制器确实接收到来自 SendGrid 的 POST 请求,但是我没有收到任何 JSON。
我尝试了以下方法:
在下面的例子中,json 为空:
public ActionResult SendGridOne(string json)
在下面的示例中,eventList 为空(注意这是使用 Sendgrid.Webhooks nuget 包):
public ActionResult SendGridOne([FromBody]SendGridEvents[] eventList)
也尝试了以下方法,但 rawSendGridJSON 始终为空:
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);
}
【问题讨论】:
-
看看
Request。Content-Type是否设置为application/json等? -
我不确定 SendGrid 不是我发送请求
-
您的控制器上有一个
Request属性。使用调试器在SendGridOne内部检查它。 -
谢谢你,我没有意识到那里。 Content-Type 确实是 application/json。唯一突出的是 HttpChannelBinding 引发了“System.UnauthorizedAccessException”类型的异常。 Microsoft 文档对此没有帮助,一些 SO 帖子说它只能在调试模式下发生......
-
尝试自己发送一些数据到您的端点,使用类似Postman。
标签: c# asp.net-mvc sendgrid