如何在 ASP.NET C# 中从 Mailgun 接收 HTTP POST?

2023-12-30

http://documentation.mailgun.net/quickstart.html http://documentation.mailgun.net/quickstart.html包含 Django 中 http 处理程序的一些示例代码:

    # Handler for HTTP POST to http://myhost.com/messages for the route defined above
    def on_incoming_message(request):
    if request.method == 'POST':
     sender    = request.POST.get('sender')
     recipient = request.POST.get('recipient')
     subject   = request.POST.get('subject', '')

     body_plain = request.POST.get('body-plain', '')
     body_without_quotes = request.POST.get('stripped-text', '')
     # note: other MIME headers are also posted here...

     # attachments:
     for key in request.FILES:
         file = request.FILES[key]
         # do something with the file

 # Returned text is ignored but HTTP status code matters:
 # Mailgun wants to see 2xx, otherwise it will make another attempt in 5 minutes
 return HttpResponse('OK')

ASP.NET C# 中的等效项是什么?

例如,我尝试过 Request.Form["sender"],但 Mailgun 日志记录了 HTTP 500 错误代码。

感谢您的帮助。


主要我希望我能在大约 6 小时前找到这个......

如果您使用 mvc 和 razor 视图引擎,则需要执行以下操作

    [HttpPost]
    [ValidateInput(false)]
    public ActionResult GoTruckGo(FormCollection oColl)
    {
        try
        {
             string sender = Request.Unvalidated().Form["sender"];
             string body =   Request.Unvalidated().Form["body-plain"];
             sendLog(body);
             // do something with data 
         }
        catch (Exception ex)
        {
            sendLog("entered catch = "+ ex.Message);
        }

        return Content("ok");

    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 ASP.NET C# 中从 Mailgun 接收 HTTP POST? 的相关文章

随机推荐