1

我想在导航到该页面之前或期间将 cookie 设置为 Webbrowser 控件。我可以在 Navigated 事件中设置 cookie,但我无法在 Webbrowser 控件的 Navigating 事件中设置 cookie。

我正在尝试下面的代码来设置cookie:

 webbrowser.InvokeScript("document.cookie=" + cookie_name+ "=" + cookie_value);

如果我尝试上面的代码,我会收到错误消息,说“发生了未知错误。错误:80020006”。

我什至尝试使用以下 URL 在 werbbrowser 控件上设置 cookie,但我仍然无法在浏览器上设置 cookie:http: //christian-helle.blogspot.in/2012/03/integrating-html5-and-javascript -with.html

编辑:

在这里,我试图为 Webbrowser 控件而不是为 HttpWebRequest 设置 cookie。我们可以为 HttpWebRequest 设置 cookie,我们可以获取 html,但 HttpWebRequest.CookieContainer 不会为 Webbrowser 设置 cookie。

提前致谢。

4

1 回答 1

-2

您可以通过以下方式获取 cookie:

CookieCollection tempCookies = Microsoft.Phone.Controls.WebBrowserExtensions.GetCookies(this.BrowserControl);

并设置它们:

string CookieHeaders = "Cookies: SomeCookie=value1; SomeCookie2=value2; SomeCookie2=value2"
this.BrowserControl.Navigate(new Uri(URL), new byte[0], CookieHeaders);
于 2013-10-11T11:51:58.397 回答