获取使用WatiN设置的Cookie列表 [英] Getting a list of cookies set using WatiN

查看:120
本文介绍了获取使用WatiN设置的Cookie列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以获取网站使用WatiN设置的所有Cookie的列表?

Is there a way to get a list of all the cookies set by a website using WatiN?

WatiN中的IE浏览器类提供了 GetCookie 方法允许您检索特定的cookie,但我想迭代所有已设置的cookie。

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.

是应该允许您获取Cookie的两种方法:

There are two methods that should allow you to get the cookies:

CookieCollection cookies = _browser.GetCookiesForUrl(new Uri(url));

CookieContainer cookies = _browser.GetCookieContainerForUrl (url));

但是这两个都是空的。同时调用特定cookie的 GetCookie 方法返回null。

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?

推荐答案

好吧,我想这些方法应该按预期工作,但也许你试图获得 HttpOnly Cookie?许多网站/ Web框架为重要的Cookie设置此标志,特别是当涉及到会话IDCookie。你不能在WatiN读它们,它真的很难阅读他们。我正在寻找解决方案一次,只有一个我得到的文章:在WebBrowser中检索HttpOnly会话Cookie

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 WebBrowser

如果您想知道您尝试获取Cookie的网站是否设置为 HttpOnly 该Cookie,请使用 Fiddler2 并查看响应标头。

If 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.

这篇关于获取使用WatiN设置的Cookie列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆