使用 WatiN 获取设置的 cookie 列表
有没有办法使用 WatiN 获取网站设置的所有 cookie 列表?
WatiN 中的 IE 浏览器类提供了一个 GetCookie
方法,允许您检索特定的 cookie,但我想迭代所有已设置的 cookie。
有两种方法可以让您获取 cookie:
CookieCollection cookies = _browser.GetCookiesForUrl(new Uri(url));
和
CookieContainer cookies = _browser.GetCookieContainerForUrl(new Uri(url) );
但这两个都是空的。调用特定 cookie 的 GetCookie
方法也会返回 null。
关于如何让它发挥作用有什么建议吗?
Is there a way to get a list of all the cookies set by a website using WatiN?
The IE Browser class in WatiN provides a GetCookie
method that allows you to retrieve a specific cookie, but I would like to iterate over all the cookies that have been set.
There are two methods that should allow you to get the cookies:
CookieCollection cookies = _browser.GetCookiesForUrl(new Uri(url));
and
CookieContainer cookies = _browser.GetCookieContainerForUrl(new Uri(url));
But both of these are empty. Also calling the GetCookie
method for a specific cookie returns null.
Any suggestions of how to get this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最近我不得不处理这种情况。起初我以为我要找的cookie是HttpOnly,但是我用WireShark看了一下,没有HttpOnly标志。
不知道为什么 GetCookieContainerForUrl 在这种情况下会失败,但客户端脚本调用显示 cookie 仍然存在:
您可能希望在每次使用数据包嗅探之前尝试该语句。
Recently I had to deal with this situation. At first I thought the cookies I was looking for were HttpOnly, but I took a look using WireShark and there was no HttpOnly flag.
Not sure why GetCookieContainerForUrl fails in this case, but a client side script call revealed the cookies were still there:
You might want to try that statement before resorting to packet sniffing every time.
好吧,我想这些方法应该按预期工作,但也许您正在尝试获取 HttpOnly cookie?许多站点/Web 框架为重要的 cookie 设置此标志,特别是当涉及“会话 id”cookie 时。你无法在 WatiN 中阅读它们,而且真的很难阅读它们。我一直在寻找解决方案,只有一篇文章: Retrieve HttpOnly Session Cookie in WebBrowser< /a>
如果您想知道您尝试获取 cookie 的网站是否在 cookie 上设置了
HttpOnly
标志,请使用 Fiddler2 并查看响应标头。Well, I suppose those methods should work as expected, but maybe you are trying to get
HttpOnly
cookies? Many sites/web frameworks sets this flag for important cookies, especially when it comes to "session id" cookies. You can't read them in WatiN and it's really hard to read them at all. I was looking for solution once and only one I got was article: Retrieve HttpOnly Session Cookie in WebBrowserIf you want to know if the site you are trying to get cookies is setting
HttpOnly
flag on the cookie, use Fiddler2 and look in response headers.