拟发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();
            }
posted @ 2012-09-19 14:38  Joe·Zhou  阅读(513)  评论(9编辑  收藏  举报