System.Net.WebClient WebClientObj = new System.Net.WebClient();
System.Collections.Specialized.NameValueCollection PostVars = new System.Collections.Specialized.NameValueCollection();
PostVars.Add("__VIEWSTATE", _viewstate);
PostVars.Add("__EVENTVALIDATION", _eventvalidation);
PostVars.Add("__EVENTTARGET", "lnkNext");
PostVars.Add("__EVENTARGUMENT", "");
PostVars.Add("Toshow", "1");
PostVars.Add("txtPage", "");
WebClientObj.Headers.Add("ContentType", "application/x-www-form-urlencoded");
try
{
byte[] byte1 = WebClientObj.UploadValues(urlStr, "POST", PostVars);
string ResponseStr = Encoding.UTF8.GetString(byte1); //得到當前頁面對應的html 文字字串
GetPostValue(ResponseStr);//得到當前頁面對應的 __VIEWSTATE 等上面需要的資訊,為抓取下一頁面使用
SaveMessage(ResponseStr);//儲存自己內容到資料庫中
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
PostVars.Add("__VIEWSTATE", _viewstate);
PostVars.Add("__EVENTVALIDATION", _eventvalidation);
PostVars.Add("__EVENTTARGET", "lnkNext");
PostVars.Add("__EVENTARGUMENT", "");
PostVars.Add("Toshow", "1");
PostVars.Add("txtPage", "");
注意:用火狐瀏覽器“網路”檢視需要POST的引數.