C#如何从GeckoWebBrowser控件获取cookie
作者:互联网
我正在使用GeckoWebBrowser控件导航URL.
加载该页面时,它实际上应该具有cookie.
但是,如果我尝试获取Cookie,即使页面已加载,我也会得到空白文本.
GeckoWebBrowser m_Browser = …
// …导航后.
字符串sCookie = m_Browser.Document.Cookie.ToString();
还有其他方法可以从GeckoWebBrowser获取cookie吗?
请帮我.
谢谢
解决方法:
已验证它可用于GeckoFX v29.0.
var uri = new Uri(txtURL.Text);
//often cookies are stored on domain level, so ".google.com", not "www.google.com" (leading dot is important)
string host = uri.Host.Replace("www", "");
var cookies = CookieManager.GetCookiesFromHost(host);
string cookiesText = "";
while (cookies.MoveNext())
{
var c = cookies.Current;
cookiesText += c.Name + "=" + c.Value + ";";
}
另外,Browser.Document.Cookie现在似乎更可靠,但是我还没有对其进行广泛的测试.
标签:geckofx,gecko,c 来源: https://codeday.me/bug/20191122/2059378.html