[英]SendGrid Event Webhook ASP.NET MVC Post is null
我希望有人可以提供幫助。 我有一個通過 Azure 運行的 ASP.NET MVC 網站。 這里的最終目標是將 SendGrid 事件記錄到數據庫中。 首先,我需要獲取 SendGrid 發送的 JSON。 我在Settings--> Mail Settings--> Event Notification
下打開了Settings--> Mail Settings--> Event Notification
。 在 Azure 和 Azure 遠程調試中使用 Postman 和 Streaming Logs,我確定我的控制器確實正在接收來自 SendGrid 的 POST 請求,但是我沒有收到任何 JSON。
我嘗試了以下方法:
在下面的示例中,json 為 null:
public ActionResult SendGridOne(string json)
在下面的示例中, eventList 為 null(注意這是使用 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);
}
Sendgrid.Webhooks nuget 包是正確的。 我用這個表格測試,它工作正常:
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Sendgrid.Webhooks.Service;
namespace WebHookSendgrid.Controllers
{
[Route("[controller]")]
[ApiController]
public class WebHookController : ControllerBase
{
// POST api/values
[HttpPost("Sendgridwh")]
public async Task<ActionResult> Sendgridwh([FromBody] object[] eventList)
{
var json = JsonConvert.SerializeObject(eventList);
var parser = new WebhookParser();
var events = parser.ParseEvents(json);
// this is custom method, you can make yours for your needs
await sendGridService.EmailActivity(events);
return new OkResult();
}
}
}
訪問 Github 上的Sendgrid Webhooks
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.