C#发送http请求
作者:admin 日期:2011-07-20
发送post数据
Encoding encoding = Encoding.GetEncoding("utf-8");
WebRequest webRequest = WebRequest.Create(http://www.zeroplace.cn);
webRequest.Method = "POST";
byte[] postData = encoding.GetBytes("?a=哈哈");
webRequest.ContentLength = postData.Length;
Stream postStream = webRequest.GetRequestStream();
postStream.Write(postData, 0, postData.Length);
postStream.Close();
WebResponse webResponse = webRequest.GetResponse();
StreamReader streamReader = new StreamReader(webResponse.GetResponseStream(), encoding);
String resHtml = streamReader.ReadToEnd();
streamReader.Close();
webResponse.Close();
Console.Write(resHtml);
评论: 0 | 查看次数: 9051