gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 16:24:31 27 4
gpt4 key购买 nike

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 View 引擎,则需要执行以下操作

    [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");

}

关于c# - 如何在 ASP.NET C# 中从 Mailgun 接收 HTTP POST?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8481325/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com