post from传值

时间:2023-01-08 14:47:49

//请求
            string url = "http://localhost:50186/GetPostPage.aspx";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

string s = "LeoTest=2013";
            byte[] requestBytes = System.Text.Encoding.UTF8.GetBytes(s);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = requestBytes.Length;
            Stream requestStream = req.GetRequestStream();
            requestStream.Write(requestBytes, 0, requestBytes.Length);
            requestStream.Close();

///1,读取
            //HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            //StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.UTF8);
            //string backstr = sr.ReadToEnd();
            //this.TextBox1.Text = backstr;

//sr.Close();
            //res.Close();

//2,打印输出
            Response.Redirect(url);

__________________________________

if (Request.Form["LeoTest"] != null)
            {
                Response.Write("OK");
            }
            else
            {
                Response.Write("ON");
            }
            Response.End();