简体   繁体   中英

Setting the cookies to webbrowser control in windows phone

I want set the cookie to Webbrowser control before or while navigating to that page. 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.

I am trying below code to set the 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."

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

Edit:

Here i am trying to set the cookie for the Webbrowser control not for the HttpWebRequest. We can set the cookie for the HttpWebRequest and we can fetch the html but HttpWebRequest.CookieContainer won't set cookie to the Webbrowser.

Thanks in advance.

You can get the cookies with this:

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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