你如何登录到一个网页,检索其在C#中的内容? [英] How do you login to a webpage and retrieve its content in C#?
本文介绍了你如何登录到一个网页,检索其在C#中的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你如何登录到一个网页,检索其在C#中的内容?
解决方案
字符串POSTDATA =用户ID =杜肯;
POSTDATA + =&放大器;用户名= camarche;
字节[]数据= Encoding.ASCII.GetBytes(POSTDATA);
WebRequest的REQ = WebRequest.Create(
URL);
req.Method =POST;
req.ContentType =应用/的X WWW的形式urlen codeD;
req.ContentLength = data.Length;
方通流= req.GetRequestStream();
newStream.Write(数据,0,data.Length);
newStream.Close();
StreamReader的读者=新的StreamReader(req.GetResponse()GetResponseStream(),System.Text.Encoding.GetEncoding(ISO-8859-1)。);
字符串COCO = reader.ReadToEnd();
How do you login to a webpage and retrieve its content in C#?
解决方案
string postData = "userid=ducon";
postData += "&username=camarche" ;
byte[] data = Encoding.ASCII.GetBytes(postData);
WebRequest req = WebRequest.Create(
URL);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = data.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream(), System.Text.Encoding.GetEncoding("iso-8859-1"));
string coco = reader.ReadToEnd();
这篇关于你如何登录到一个网页,检索其在C#中的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文