1. 程式人生 > >C# get與post請求,在一般處理程式handler中的應用Request.QueryString和Request.Form的用法,利用postman工具進行請求

C# get與post請求,在一般處理程式handler中的應用Request.QueryString和Request.Form的用法,利用postman工具進行請求

一、Get 請求

1.引數存放在請求頭中header。(postman工具能夠證明,Body不可選)

2.字串大小有限制,需要小於2k位元組。

3. handler 接受引數Request.QueryString 或 Request,說明其實Request獲取值還是通過Request.QueryString查詢的

public class HLLHandler1 : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        //get 請求
        var test1 = context.Request.QueryString["ID"];  //  test1 = 12 
        var test2 = context.Request.Form["ID"];  // test1 = null
        var test3 = context.Request["ID"];  // test1 = 12 
    }

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

二、Post 請求

  1. 1.引數存放在body中。

2.字串大小無限制。

3. handler 接受引數Request.Form或 Request,說明其實Request獲取值還是通過Request.Form查詢的

public class HLLHandler1 : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        //Post 請求
        var test1 = context.Request.QueryString["ID"];  //  test1 = null 
        var test2 = context.Request.Form["ID"];  // test1 = null
        var test3 = context.Request["ID"];  // test1 = null 

        var test4 = context.Request.QueryString["NAME"];  //  test4 = null 
        var test5 = context.Request.Form["NAME"];  // test5 = TEST
        var test6 = context.Request["NAME"];  // test6 = TEST 
    }

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