日期:2014-05-17 浏览次数:20482 次
HttpWebRequest webrequest = WebRequest.Create("http://passport.csdn.net/account/login") as HttpWebRequest; webrequest.ContentType = "application/x-www-form-urlencoded"; webrequest.CookieContainer = new CookieContainer(); webrequest.Method = "POST"; string arg = string.Format("u={0}&p={1}", "tiandiyuzhou1", "abcdefg"); byte[] data = Encoding.ASCII.GetBytes(arg); webrequest.ContentLength = data.Length; using (Stream reqStream = webrequest.GetRequestStream()) { reqStream.Write(data, 0, data.Length); } HttpWebResponse webresponse = webrequest.GetResponse() as HttpWebResponse; using (StreamReader reader = new StreamReader(webresponse.GetResponseStream())) { Response.Write(reader.ReadToEnd()); } /* 这里第1点:为什么不管用户密码输入是否正确,返回的都是下面那个图? 怎么获取不到是否登陆成功或失败? —/ foreach (Cookie coo in webresponse.Cookies) Response.Write(coo.Name + "==" + coo.Value + "<br/>"); /* 这里第2点:我把地址改为http://community.csdn.net/WebNavigation/ForumContent.aspx这个, 为什么获取到的Cookie总是 UserName== UserInfo== 获取不到value值呢? */