henrikh
henrikh

Reputation: 113

UWP Get cookie from website

I am using a WebView in a Windows 10 Mobile app.

After the user has entered his credentials on a webpage in the WebView a redirection happens. When the webpage that was redirected to has loaded, I am going to get a cookie in order to get a token.

I have looked into WebView, but cannot find anything about cookies.

Is it possible to get cookies from the WebView?

I have looked into Windows.Web.Http.HttpClient and seen that it should be possible to retrieve a cookie using HttpClient. Is Windows.Web.Http.HttpClient the way to go? If so, how should I go about to get a cookie from WebView using the HttpClient?

Help appreciated, thanks!

Upvotes: 4

Views: 1711

Answers (1)

khamitimur
khamitimur

Reputation: 1088

Using WebBrowser in your app after redirect happens you can get cookies for redirected URL like this:

private HttpCookieCollection GetBrowserCookie(Uri targetUri)
{
   var httpBaseProtocolFilter = new HttpBaseProtocolFilter();
   var cookieManager = httpBaseProtocolFilter.CookieManager;
   var cookieCollection = cookieManager.GetCookies(targetUri);

   return cookiesCollection;
}

Upvotes: 4

Related Questions