Pradeep devendran
Pradeep devendran

Reputation: 489

Set cookies to WebView Control

I have cookies which taken from HttpWebRequest and I need to set these cookies to WebView control to another page.

How can I transfer these cookie to WebView control in windows 8.1 Store app?

Upvotes: 6

Views: 4845

Answers (1)

Pradeep devendran
Pradeep devendran

Reputation: 489

I got an answer on MSDN and it works well for me.

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
}

Upvotes: 8

Related Questions