问题描述
- cookiecontainer问题,折腾一天了求帮助谢谢
-
我把httpwebresponse.cokies添加add()到cookiecontaoner里,然后遍历出来,里面的cookie不全(还就是关键的几个cookie没在),然后我又直接遍历httpwebresponse.cokies,里面的cookie又全在,请问下这是怎么回事??///?<summary>?? ///?通过get方式请求页面,传递一个实例化的cookieContainer?? ///?</summary>?? ///?<param?name="postUrl"></param>?? ///?<param?name="cookie"></param>?? ///?<returns></returns>?? public?static?ArrayList?GetHtmlData(string?postUrl,?CookieContainer?cookie)?? {?? ????HttpWebRequest?request;?? ????HttpWebResponse?response;?? ????ArrayList?list?=?new?ArrayList();?? ????request?=?WebRequest.Create(postUrl)?as?HttpWebRequest;?? ????request.Method?=?"GET";?? ????request.UserAgent?=?"Mozilla/4.0";?? ????request.CookieContainer?=?cookie;?? ????request.KeepAlive?=?true;?? ?? ????request.CookieContainer?=?cookie;?? ????try?? ????{?? ????????//获取服务器返回的资源?? ????????using?(response?=?(HttpWebResponse)request.GetResponse())?? ????????{?? ????????????using?(StreamReader?reader?=?new?StreamReader(response.GetResponseStream(),?Encoding.Default))?? ????????????{?? ????????????????cookie.Add(response.Cookies);?? ????????????????//保存Cookies?? ????????????????list.Add(cookie);?? ????????????????list.Add(reader.ReadToEnd());?? ????????????????list.Add(Guid.NewGuid().ToString());//图片名?? ????????????}?? ????????}?? ????}?? ????return?list; }
解决方案
http://www.cnblogs.com/forcertain/archive/2012/12/04/2801224.html
fiddler调试下
解决方案二:
cookiecontaoner 里的cookie 不全是怎么回事
解决方案三:
dotnet framework 4.0左右的版本的System.Net.CookieContainer默认只支持 RFC 2109 和 RFC 2965 格式的Cookie, 对于最近的rfc2616 格式的Cookie直接略过,仁兄还是自己解析吧
时间: 2024-10-03 22:31:02