允许 C# 接受和处理 POST 请求

Allow C# to accept and deal with POST requests

本文关键字:处理 POST 请求 允许      更新时间:2023-09-26

我最近一直在为一个 ASP.NET 项目编写一个 C# 自定义 API,我的问题是,我如何实现一段代码,允许我接受 POST 请求,然后创建一个 SQL 查询,然后将其插入数据库。(如果需要,我可以使用JS)

帕斯特宾链接:http://pastebin.com/mMN4cZwd

我也知道我的代码目前容易受到SQL注入的影响,但不要担心自己!

创建一个处理程序( receivepost.ashx),然后:

public class receivepost : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {

        if (context.Request.Form["order_id"] != null)
        {
            int orderID = Convert.ToInt32(context.Request["order_id"]);
            // SQL SYNTAX TO SAVE ORDERID IN TO DATABASE
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

您的处理程序将从外部调用,例如: www.yourdomain.com/tools/receivepost.ashx