set cookies/headers for webview via code for Win Store App

前端 未结 2 509
挽巷
挽巷 2020-12-19 16:04

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?

<
相关标签:
2条回答
  • 2020-12-19 16:12

    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);
    
    0 讨论(0)
  • 2020-12-19 16:23

    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.

    0 讨论(0)
提交回复
热议问题