编程语言
首页 > 编程语言> > c#-将cookie设置为WebView控件

c#-将cookie设置为WebView控件

作者:互联网

我有从HttpWebRequest获取的cookie,我需要将这些cookie设置为WebView控件的另一个页面.

如何将这些cookie传输到Windows 8.1 Store应用程序中的WebView控件?

解决方法:

我得到了answer on MSDN,对我来说效果很好.

try
{
    Uri baseUri = new Uri(txtURI.Text);
    Windows.Web.Http.Filters.HttpBaseProtocolFilter filter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
    Windows.Web.Http.HttpCookie cookie = new Windows.Web.Http.HttpCookie("cookieName", baseUri.Host, "/");
    cookie.Value = "cookieValue";
    filter.CookieManager.SetCookie(cookie, false);

    Windows.Web.Http.HttpRequestMessage httpRequestMessage = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Get, baseUri);
    wvTest.NavigateWithHttpRequestMessage(httpRequestMessage);

}
catch (Exception oEx)
{
    // handle exception
}

标签:uwp,windows-runtime,windows-store-apps,c
来源: https://codeday.me/bug/20191029/1963376.html