CookieContainer cc = new CookieContainer();
string postData = "id=admin&password=123456";
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化 HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(new Uri("http://www.linezing.com/login.php"));
webRequest2.CookieContainer = cc;
webRequest2.Method = "POST";
webRequest2.ContentType = "application/x-www-form-urlencoded";
webRequest2.ContentLength = byteArray.Length;
Stream newStream = webRequest2.GetRequestStream(); newStream.Write(byteArray, 0, byteArray.Length); //写入参数
newStream.Close(); HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
StreamReader sr2 = new StreamReader(response2.GetResponseStream(), Encoding.Default); string text2 = sr2.ReadToEnd();
Label1.Text = text2;这段代码有什么问题?老是获取不到。CookieHttpWebRequest
string postData = "id=admin&password=123456";
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化 HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(new Uri("http://www.linezing.com/login.php"));
webRequest2.CookieContainer = cc;
webRequest2.Method = "POST";
webRequest2.ContentType = "application/x-www-form-urlencoded";
webRequest2.ContentLength = byteArray.Length;
Stream newStream = webRequest2.GetRequestStream(); newStream.Write(byteArray, 0, byteArray.Length); //写入参数
newStream.Close(); HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
StreamReader sr2 = new StreamReader(response2.GetResponseStream(), Encoding.Default); string text2 = sr2.ReadToEnd();
Label1.Text = text2;这段代码有什么问题?老是获取不到。CookieHttpWebRequest
http://www.cnblogs.com/insus/articles/2055310.html稍复杂一点的:
http://www.cnblogs.com/insus/articles/2055531.html