读书人

小弟我在模拟登陆的时候 获取不到cook

发布时间: 2012-05-30 20:20:04 作者: rapoo

我在模拟登陆的时候 获取不到cookie
我想模拟下人人自动登陆 然后再打开新的链接,我使用一下代码 获取cookie 但得到的是"";没有获取到任何的值,很是郁闷 请高手指点。我断点后发现 mycookie得到空值,

C# code
                Test.HttpHeader header = new Test.HttpHeader();            header.accept = "itext/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";            header.contentType = "application/x-www-form-urlencoded";            header.method = "POST";            header.userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";            header.maxTry = 300;CookieCollection mycookie = Test.HTMLHelper.GetCookieCollection("http://www.renren.com/PLogin.do",            //                   "mail=bgaidu%40163.com&password=123456789&origURL=https%3A%2F%2Fsafe.renren.com%2F&domain=renren.com&formName=&method=&isplogin=true&submit=%E7%99%BB%E5%BD%95", header);




然后我又断点 getcookiecollection 方法的代码如下,得到的也为空值。



C# code
   HttpWebRequest request = null;            HttpWebResponse response = null;            try            {                CookieContainer cc = new CookieContainer();                request = (HttpWebRequest)WebRequest.Create(loginUrl);                request.Method = header.method;                request.ContentType = header.contentType;                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();                //接收响应                response = (HttpWebResponse)request.GetResponse();                response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);                CookieCollection cook = response.Cookies;                //Cookie字符串格式                string strcrook = request.CookieContainer.GetCookieHeader(request.RequestUri);                return cook;            }            catch (Exception ex)            {                throw ex;            }


求高手指点!

[解决办法]
可能根本没有cookie...
[解决办法]
Look this
http://www.cnblogs.com/top5/archive/2010/12/14/1905963.html
[解决办法]
试了一下 访问PLogin.do没有产生cookie
页面将跳转到SysHome.do 此时将会有cookie
建议使用一些抓包工具协作分析。。。
[解决办法]
那到底Plogin.do有没有cookie呢

读书人网 >C#

热点推荐