我有从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
}