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




[本日志由 admin 于 2011-07-20 10:35 AM 编辑]

有什么问题可以加群,100852896
点击这里加入此群 在线提问
文章来自: 本站原创
Tags:
评论: 0 | 查看次数: 6362
博主QQ: 友情链接请找我
QQ群: 灰色档案
返回顶部 关闭