async void defaultHttpAuthHandler(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
 {
     var exception = e.Exception as WebBrowserNavigationException;
     if (exception != null && exception.StatusCode == System.Net.HttpStatusCode.Unauthorized)
     {
         Debug.WriteLine("Got 401 while navigating to " + e.Uri.ToString());
         var handler = new HttpAuthRequestHandler();
         e.Handled = await handler.handle(sender as WebBrowser, e.Uri);
         if (e.Handled)
         {
             ((WebBrowser)sender).Navigate(e.Uri);
         }
     }
 }
        async void defaultHttpAuthHandler(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
        {
            var exception = e.Exception as WebBrowserNavigationException;

            if (exception != null && exception.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                Debug.WriteLine("Got 401 while navigating to " + e.Uri.ToString());
                var handler = new HttpAuthRequestHandler();
                e.Handled = await handler.handle(sender as WebBrowser, e.Uri);

                if (e.Handled)
                {
                    ((WebBrowser)sender).Navigate(e.Uri);
                }
            }
        }
        public void requestCredentials(string jsonArgs)
        {
            var args = JsonHelper.Deserialize<string[]>(jsonArgs);
            var uri = new System.Uri(args[0]);

            Deployment.Current.Dispatcher.BeginInvoke(async () =>
            {
                string creds;
                var handler = new HttpAuthRequestHandler();
                try
                {
                    var credentials = await handler.requestCredentials(uri);
                    creds = JsonHelper.Serialize(credentials);
                    DispatchCommandResult(new PluginResult(PluginResult.Status.OK, creds));
                }
                catch (System.Threading.Tasks.TaskCanceledException)
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR));
                }
            });
        }
        public void requestCredentials(string jsonArgs)
        {
            var args = JsonHelper.Deserialize <string[]>(jsonArgs);
            var uri  = new System.Uri(args[0]);

            Deployment.Current.Dispatcher.BeginInvoke(async() =>
            {
                string creds;
                var handler = new HttpAuthRequestHandler();
                try
                {
                    var credentials = await handler.requestCredentials(uri);
                    creds           = JsonHelper.Serialize(credentials);
                    DispatchCommandResult(new PluginResult(PluginResult.Status.OK, creds));
                }
                catch (System.Threading.Tasks.TaskCanceledException)
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR));
                }
            });
        }