62,046
社区成员
发帖
与我相关
我的任务
分享
string strLoginUrl = "提交地址";
string strLoginUrlPost = "提交内容";
HttpWebRequest reqLogin = (HttpWebRequest)WebRequest.Create(strLoginUrl);
reqLogin.KeepAlive = true;
reqLogin.Method = "POST";
reqLogin.AllowAutoRedirect = true;
reqLogin.UseDefaultCredentials = true;
// reqLogin.Referer = strLoginPageUrlReferer;
reqLogin.UserAgent ="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 1.1.4322; .NET CLR 3.5.20404)";
reqLogin.ContentType = "application/x-www-form-urlencoded";
reqLogin.CookieContainer = new CookieContainer();
//reqLogin.CookieContainer.Add(ccFirstPage);
reqLogin.ContentLength = strLoginUrlPost.Length;
//POST 提交
StreamWriter sw2 = new StreamWriter(reqLogin.GetRequestStream());
sw2.Write(strLoginUrlPost);
sw2.Close();
//得到提交之后的返回数据
HttpWebResponse resLogin = (HttpWebResponse)reqLogin.GetResponse();
resLogin.Cookies = reqLogin.CookieContainer.GetCookies(reqLogin.RequestUri);
//返回的Header
Debug.Write("\n Header >> " + reqLogin.Headers.ToString());
StreamReader sr2 = new StreamReader(resLogin.GetResponseStream());
String strAftLoginPage = sr2.ReadToEnd();
sr2.Close();
CookieCollection ccLogin = new CookieCollection();
ccLogin.Add(resLogin.Cookies);
//response url url
string strREsponseUrlTemp = resLogin.ResponseUri.ToString();
resLogin.Close();
reqLogin.Abort();