日期:2014-05-17  浏览次数:20738 次

c# 如何模拟登陆后操作
c# 如何模拟登陆后操作
这段代码 在不需要登陆的页面操作没有问题 但需要登陆的页面 就不行 不知道该如何修改请教了

               HttpWebRequest request = null;
               HttpWebResponse response = null;
               //CookieContainer cc = new CookieContainer();
               request = (HttpWebRequest)WebRequest.Create(loginUrl);
               request.Method = "POST";
               request.ContentType = "application/x-www-form-urlencoded";
               byte[] postdatabyte = Encoding.UTF8.GetBytes(postdata);
               request.ContentLength = postdatabyte.Length;
               request.AllowAutoRedirect = false;
               //request.CookieContainer = cc;
               request.KeepAlive = true;
               Stream stream;
               stream = request.GetRequestStream();
               stream.Write(postdatabyte, 0, postdatabyte.Length);
               stream.Close();

------解决方案--------------------
要想保持登录,需要附加上服务器给你的cookie
------解决方案--------------------
Cookie问题,如果是登录的话,一定伴随的Cookie的