Reputation: 5104
I want to set cookies for my webview
via the code. I know it was not possible in windows phone. But is it now possible in windows 8? Can anyone guide me?
Alternate Option: Can I pass Headers while navigating to a URL in windows 8?
In windows phone
Navigate(URL, [Flags,] [TargetFrameName,] [PostData,] [Headers])
In Windows 8
Navigate(Uri source)
Upvotes: 4
Views: 2835
Reputation: 16420
In Windows 8.1 and Windows 10 you can do:
// using Windows.Web.Http;
// using Windows.Web.Http.Filters;
Uri uri = new Uri("http://kiewic.com/your/url/");
HttpCookie cookie = new HttpCookie("fooName", uri.Host, "/");
cookie.Value = "barValue";
HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
HttpCookieManager cookieManager = filter.CookieManager;
cookieManager.SetCookie(cookie, false);
MyWebView.Navigate(uri);
Upvotes: 2
Reputation: 2026
Sorry but the WebView control won't do that for you.
You can acomplish what you want creating a custom WebRequest with the desired headers, and then call WebView.NavigateToString() with the content of the WebResponse.
Upvotes: 1