拟发http请求处理响应

            string data = "Name=zhoulq&Sex=" + HttpUtility.UrlEncode("");

            byte[] msg=Encoding.UTF8.GetBytes(data);

            HttpWebRequest req = HttpWebRequest.Create("http://localhost:1256/Accept.aspx") as HttpWebRequest;

            req.ContentType = "application/x-www-form-urlencoded";

            req.ContentLength = msg.Length;

            req.Method = "POST";

            using (Stream stream=req.GetRequestStream())

            {

                stream.Write(msg, 0, msg.Length);

            }

            using (HttpWebResponse rsp = req.GetResponse() as HttpWebResponse)

            {

                Stream stream=rsp.GetResponseStream();

                StreamReader sr = new StreamReader(stream,Encoding.UTF8);

                lta.Text = sr.ReadToEnd();

                sr.Close();

                stream.Close();

            }

你可能感兴趣的:(http)