可以使用 Visual Sniffer(百度搜尋) 來捕捉送出的資料資訊:
2. 填寫好需要的資料,比如使用者名和密碼,
3. 打開 Visual Sniffer, 點“開始攔截”
4. 在通路的頁面中送出。
5. 等送出成功之後,在 Visual Sniffer 中“停止攔截”
6. 在 Visual Sniffer 的左側欄的加号中依次點開,右邊是它攔截到的内容:

POST http://www.csdn.net/member/UserLogin.aspx HTTP/1.0
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Referer: http://www.csdn.net/member/UserLogin.aspx
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Pragma: no-cache
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; InfoPath.1)
Host: www.csdn.net
Content-Length: 355
Proxy-Connection: Keep-Alive
Cookie: ASPSESSIONIDAAAATBQC=FMEGGCKDBKHAMMCGKPFDMBFG; ASP.NET_SessionId=lusprmnom05lr445tmteaf55; userid=699879
__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=dDwtMTcwMzgxNjQ2Mjs7bDxDU0ROVXNlckxvZ2luOmNiX1NhdmVTdGF0ZTtDU0ROVXNlckxvZ2luOkltYWdlX0xvZ2luOz4%2Btu1q2wmRZoAJTi9L73w1zBleylY%3D&CSDNUserLogin%3Atb_UserName=testusername&CSDNUserLogin%3Atb_Password=testpassword&CSDNUserLogin%3Atb_ExPwd=9232&from=&CSDNUserLogin%3AImage_Login.x=36&CSDNUserLogin%3AImage_Login.y=6
GET http://www.csdn.net/mycustompage.htm?aspxerrorpath=/member/UserLogin.aspx HTTP/1.0
以上為攔截内容,其中送出資料的參數部分(程式中的:strArgs)如:
__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=dDwtMTcwMzgxNjQ2Mjs7bDxDU0ROVXNlckxvZ2luOmNiX1NhdmVTdGF0ZTtDU0ROVXNlckxvZ2luOkltYWdlX0xvZ2luOz4%2Btu1q2wmRZoAJTi9L73w1zBleylY%3D&CSDNUserLogin%3Atb_UserName=testusername&CSDNUserLogin%3Atb_Password=testpassword&CSDNUserLogin%3Atb_ExPwd=9232

protected static string cookieHeader;
private void Page_Load(object sender, System.EventArgs e)

{
string strReContent = string.Empty;
//登入
strReContent = PostLogin("http://www.mystand.com.cn/login/submit.jsp送出的頁面","送出的參數:userid=hgj0000&password=06045369","引用位址:http://www.mystand.com.cn/");
//asp.net登入傳遞的參數需注意
//strReContent = PostLogin("http://www.mystand.com.cn/login.aspx","__VIEWSTATE=dDwtNjkzMjUyNDczO3Q8O2w8aTwzPjs%2BO2w8dDxwPHA8bDxUZXh0Oz47bDxcZTs%2BPjs%2BOzs%2BOz4%2BOz6aX2dtqkJTK%2BKbNPsjd7Op%2Fl26Iw%3D%3D&txtUserName=hxf&txtPassword=hxf0000&btnEnter=%E7%99%BB%E5%BD%95","http://www.mystand.com.cn/login.aspx");
//擷取頁面
strReContent = GetPage("http://www.mystand.com.cn/company/getdata.jsp?code=","引用位址:http://www.mystand.com.cn/");
//strReContent = GetPage("http://www.mystand.com.cn/Modules/index.aspx","http://www.mystand.com.cn/login.aspx");
//可以對獲得的内容進行處理:strReContent
}

/// <summary>
/// 功能描述:模拟登入頁面,送出登入資料進行登入,并記錄Header中的cookie
/// </summary>
/// <param name="strURL">登入資料送出的頁面位址</param>
/// <param name="strArgs">使用者登入資料</param>
/// <param name="strReferer">引用位址</param>
/// <returns>可以傳回頁面内容或不傳回</returns>
public static string PostLogin(string strURL,string strArgs,string strReferer)

string strResult = "";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
myHttpWebRequest.AllowAutoRedirect = true;
myHttpWebRequest.KeepAlive = true;
myHttpWebRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*";
myHttpWebRequest.Referer = strReferer;
myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 2.0.50727)";
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
myHttpWebRequest.Method = "POST";
CookieCollection myCookies = null;
CookieContainer myCookieContainer = new CookieContainer();
myHttpWebRequest.CookieContainer = myCookieContainer;
Stream MyRequestStrearm = myHttpWebRequest.GetRequestStream();
StreamWriter MyStreamWriter = new StreamWriter(MyRequestStrearm,Encoding.ASCII);
//把資料寫入HttpWebRequest的Request流
MyStreamWriter.Write(strArgs);
//關閉打開對象
MyStreamWriter.Close();
MyRequestStrearm.Close();
HttpWebResponse response = null;
System.IO.StreamReader sr = null;
response = (HttpWebResponse)myHttpWebRequest.GetResponse();
cookieHeader = myHttpWebRequest.CookieContainer.GetCookieHeader(new Uri(strURL));
HttpContext.Current.Application.Lock();
HttpContext.Current.Application["cookieHeader"] = cookieHeader;
HttpContext.Current.Application.UnLock();
myCookies = response.Cookies;
sr = new System.IO.StreamReader(response.GetResponseStream(),Encoding.GetEncoding("gb2312")); // //utf-8
strResult = sr.ReadToEnd();
return strResult;

/// 功能描述:在PostLogin成功登入後記錄下Headers中的cookie,然後擷取此網站上其他頁面的内容
/// <param name="strURL">擷取網站的某頁面的位址</param>
/// <param name="strReferer">引用的位址</param>
/// <returns>傳回頁面内容</returns>
public static string GetPage(string strURL,string strReferer)

myHttpWebRequest.ContentType = "text/html";
myHttpWebRequest.Method = "GET";
myHttpWebRequest.Headers.Add("cookie:"+ cookieHeader);
sr = new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312")); // //utf-8
本文轉自94cool部落格園部落格,原文連結:http://www.cnblogs.com/94cool/articles/1532591.html,如需轉載請自行聯系原作者