6

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

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

4

1 回答 1

8

在 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
}
于 2014-03-04T15:57:33.423 回答