How do you login to a webpage and retrieve its content in C#?

前端 未结 7 2031
孤街浪徒
孤街浪徒 2020-12-30 17:13

How do you login to a webpage and retrieve its content in C#?

相关标签:
7条回答
  • 2020-12-30 18:03
    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();
    
    0 讨论(0)
提交回复
热议问题