.net webrequest应用



StringBuilder sb = new StringBuilder("data=1");


byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString());


WebRequest req = WebRequest.Create("http://baidu.com?");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = bytes.Length;


Stream reqSt = req.GetRequestStream();
reqSt.Write(bytes, 0, bytes.Length);
reqSt.Close();


WebResponse rep = req.GetResponse();
Stream st = rep.GetResponseStream();


StreamReader reader = new StreamReader(st);
string txt = reader.ReadToEnd();
reader.Close(); st.Close();
}
posted @ 2012-12-27 15:17  y0umer  阅读(117)  评论(0编辑  收藏  举报