I need to display a few of webpages from a remote Apache webserver for the IoT Core app I'm developing. I've used the WebView class method .Navigate() for non-protected pages and It works really neat. However, for my project, I need to login first into the webserver (username + password) and then retrieve the info from the pages, but I don't know how to do it using the WebView class. I'm clueless.
I found a solution that uses the WebBrowser class Navigate(), sending the credentials as a 64 base encoded string, but the Navigate() of WebView only allows 1 argument, the URI, and nothing else. I can't seem to find WebBrowser class neither.
I've already tried to embed the username/password into the URI but It's not working properly and I'm aware It's not a good idea to do it so.
Is it possible to achieve this using WebView?Any suggestions/ideas?
Any help appreciated
Edit: I've found a solution that works well for my problem, I'm posting it in case it can be of help to someone with similar issues.
Uri req_uri = new Uri(uri_list[i]);
HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
filter.ServerCredential = new PasswordCredential(req_uri.ToString(), "username", "password");
HttpCookieCollection cookiejar = filter.CookieManager.GetCookies(req_uri);
if (cookiejar.Count > 0)
{
foreach (HttpCookie cookie in cookiejar)
{
filter.CookieManager.SetCookie(cookie);
}
}
Windows.Web.Http.HttpClient client = new Windows.Web.Http.HttpClient(filter);
Windows.Web.Http.HttpRequestMessage http_req = new Windows.Web.Http.HttpRequestMessage();
http_req.Method = Windows.Web.Http.HttpMethod.Get;
http_req.RequestUri = req_uri;
var clientResponse = client.GetAsync(req_uri);
webView.NavigateWithHttpRequestMessage(http_req);
http_req.Dispose();
client.Dispose();