C#发送http请求

发送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);



文章来自: 本站原创
Tags:
评论: 0 | 查看次数: 9051