Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 766
henrikh Avatar asked Sep 18 '25 02:09

henrikh


1 Answers

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;
}
like image 80
khamitimur Avatar answered Sep 20 '25 18:09

khamitimur