bigfun4000

【C#源码】Discuz论坛登录源码

/// /// 登陆Discuz论坛 文章来源:酷趣网 /// /// 登陆后返回的cookie public CookieContainer login(string usrname, string paw, string login_url) { #region 初始化登陆信息 文章来源:酷趣网 string strId = usrname; string strPassword = paw; string loginsubmit = "true"; string formhash = "10405a6f"; string cookietime = "315360000"; CookieContainer cc = new CookieContainer(); ASCIIEncoding encoding = new ASCIIEncoding(); string postData = "&loginsubmit=" + loginsubmit + "&formhash=" + formhash + "&cookietime=" + cookietime + "&loginfield=username&username=" + strId + "&password=" + strPassword; byte[] data = Encoding.UTF8.GetBytes(postData); #endregion try { // Prepare web request 文章来源:酷趣网 HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(new Uri(login_url)); myRequest.CookieContainer = cc; myRequest.Method = "POST"; myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"; myRequest.ContentType = "application/x-www-form-urlencoded"; myRequest.ContentLength = data.Length; Stream newStream = myRequest.GetRequestStream(); // Send the data. newStream.Write(data, 0, data.Length); newStream.Close(); // Get response 文章来源:酷趣网 HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding("gbk")); StringBuilder builder = new StringBuilder(); string tempPath = reader.ReadToEnd(); reader.Close(); myResponse.Close(); } catch (WebException webEx) { return null; } return cc; //返回cookie 文章来源:酷趣网 }

posted on 2010-10-12 17:46  bigfun4000  阅读(972)  评论(0编辑  收藏  举报

导航