4

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)
Milan Aggarwal
  • 5,104
  • 3
  • 25
  • 54

2 Answers2

2

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);
kiewic
  • 15,852
  • 13
  • 78
  • 101
1

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.

Daniel San
  • 1,937
  • 3
  • 19
  • 36
  • 1
    I have done this too but in that case the parameters I set go as post parameter and not as header or cookies. Could you help me with some code? Also the content I receive contains JS functions which throw error. Is it because the JS is not present when I do NavigateToString? – Milan Aggarwal Nov 20 '12 at 14:43