简体   繁体   English

在Windows Phone中将Cookie设置为Web浏览器控件

[英]Setting the cookies to webbrowser control in windows phone

I want set the cookie to Webbrowser control before or while navigating to that page. 我想在浏览到该页面之前或同时将cookie设置为Webbrowser控件。 I am able to set the cookie in the Navigated event but i am not able set the cookie in the Navigating event of Webbrowser control. 我可以在Navigated事件中设置cookie,但不能在Webbrowser控件的Navigating事件中设置cookie。

I am trying below code to set the cookie: 我正在尝试下面的代码来设置cookie:

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

If i try the above code i am getting error saying that "An unknown error has occurred. Error: 80020006." 如果我尝试上述代码, 则会收到错误消息,提示“发生未知错误。错误:80020006。”

I even tried below URL to set the cookie on the werbbrowser control but still i am not able to set the cookie on the browser: http://christian-helle.blogspot.in/2012/03/integrating-html5-and-javascript-with.html 我什至尝试在URL下面设置werbbrowser控件上的cookie,但仍然无法在浏览器上设置cookie: http : //christian-helle.blogspot.in/2012/03/integrating-html5-and-javascript -with.html

Edit: 编辑:

Here i am trying to set the cookie for the Webbrowser control not for the HttpWebRequest. 在这里,我试图为Webbrowser控件而不是为HttpWebRequest设置cookie。 We can set the cookie for the HttpWebRequest and we can fetch the html but HttpWebRequest.CookieContainer won't set cookie to the Webbrowser. 我们可以为HttpWebRequest设置cookie,也可以获取html,但是HttpWebRequest.CookieContainer不会将cookie设置为Webbrowser。

Thanks in advance. 提前致谢。

You can get the cookies with this: 您可以通过以下方式获取Cookie:

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

And set them with this: 并为此设置它们:

string CookieHeaders = "Cookies: SomeCookie=value1; SomeCookie2=value2; SomeCookie2=value2"
this.BrowserControl.Navigate(new Uri(URL), new byte[0], CookieHeaders);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM