程序登陆网站并获取页面返回信息。
private void button2_Click(object sender, EventArgs e)
{
string usename = txt_name.Text.ToString().Trim();
string password = txt_psw.Text.ToString().Trim();
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://127.0.0.1:90/http/loginBackground.aspx");
WebClient wc = new WebClient();
string s = "username=" + usename + "&" + "password=" + password;
byte[] bs = Encoding.UTF8.GetBytes(s);
req.Method = "POST";
req.ContentLength = bs.Length;
req.ContentType = "application/x-www-form-urlencoded";
req.GetRequestStream().Write(bs, 0, bs.Length);
var resp = (HttpWebResponse)req.GetResponse();
string result = new System.IO.StreamReader(resp.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312")).ReadToEnd();
MessageBox.Show(result);
}