ASP.NET 处理get/post数据方式

1.GET方式

    NameValueCollection coding;
    coding = HttpUtility.ParseQueryString(Request.Url.Query, Encoding.GetEncoding("UTF-8"));
    Response.Write("coding[name]");
    Response.End();
    

说明:coding就是获取get传过来的键值对的变量。使用的时候就是 coding['key']得到value。当然也是key=value&key=value这种形式。

2.POST方式

    var inputStream = Request.InputStream;
    var strLen = Convert.ToInt32(inputStream.Length);
    var strArr = new byte[strLen];
    inputStream.Read(strArr, 0, strLen);
    var requestMes = Encoding.UTF8.GetString(strArr);
    var arr = requestMes.Split('=');
    inputStream.Close();
    inputStream.Dispose();
    Response.Write("alert('hello " + arr[1] + "!');");
    Response.End();
    

说明:requestMes变量用来得到post过来的信息,存的方式是key=value&key=value这种形式。但是requestMsg是字符串,不支持上面coding那种取值的方式。