当前位置: 首页>>代码示例>>C#>>正文


C# WebView.NavigateWithHttpRequestMessage方法代码示例

本文整理汇总了C#中Windows.UI.Xaml.Controls.WebView.NavigateWithHttpRequestMessage方法的典型用法代码示例。如果您正苦于以下问题:C# WebView.NavigateWithHttpRequestMessage方法的具体用法?C# WebView.NavigateWithHttpRequestMessage怎么用?C# WebView.NavigateWithHttpRequestMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.UI.Xaml.Controls.WebView的用法示例。


在下文中一共展示了WebView.NavigateWithHttpRequestMessage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteAsync

        public async Task<string> ExecuteAsync(WebView webView, Grid owner)
        {
            var url = string.Format("{0}?response_type=code&client_id={1}&redirect_uri={2}", OAuthSettings.AuthorizeEndpoint,
               Uri.EscapeDataString(OAuthSettings.ClientId),
               Uri.EscapeDataString("https://returnurl"));


            TaskCompletionSource<string> tcs = new TaskCompletionSource<string>();


            webView.NavigationStarting += async (s, a) =>
            {
                if (a.Uri.ToString().StartsWith("https://returnurl"))
                {
                    // detect return url
                    owner.Children.Remove(webView);
                    if (a.Uri.Query.StartsWith("?code="))
                    {
                        var code = Uri.UnescapeDataString(a.Uri.Query.Substring(6));
                        using (var client = new HttpClient())
                        {
                            var content = new HttpFormUrlEncodedContent(new Dictionary<string, string>{
                                {"grant_type","authorization_code"},
                                {"code", code},
                                {"redirect_uri", "https://returnurl"},
                                {"client_id", OAuthSettings.ClientId},
                                {"client_secret", OAuthSettings.ClientSecret}
                            });
                            // exchange authorize code for an access token
                            var response = await client.PostAsync(new Uri(OAuthSettings.TokenEndpoint), content);
                            response.EnsureSuccessStatusCode();
                            var contentString = await response.Content.ReadAsStringAsync();
                            var accessTokenInfo = await JsonConvert.DeserializeObjectAsync<OAuthTokenInfo>(contentString);
                            OAuthSettings.AccessToken = accessTokenInfo.AccessToken;
                            OAuthSettings.RefreshToken = accessTokenInfo.RefreshToken;

                            tcs.SetResult(accessTokenInfo.AccessToken);
                        }
                    }
                }
            };
            webView.NavigateWithHttpRequestMessage(new HttpRequestMessage(HttpMethod.Get, new Uri(url)));


            return await tcs.Task;
        }
开发者ID:jcorioland,项目名称:techdays-paris-2014-mvc-webapi,代码行数:46,代码来源:LoginInteractivelyAsync.cs

示例2: OnWebviewClick

        private async void OnWebviewClick(object sender, RoutedEventArgs e)
        {
            await EnsureLoggedInAsync();

            var webView = new WebView() { Margin = new Thickness(50) };

            webView.Loaded += (s, a) =>
            {
                var message = new HttpRequestMessage(HttpMethod.Get, new Uri("http://localhost:20394/demowebviewauth"));
                //message.Headers.Authorization = new HttpCredentialsHeaderValue("Bearer", OAuthSettings.AccessToken);
                webView.NavigateWithHttpRequestMessage(message);
            };

            Grid.SetRow(webView, 1);

            layoutRoot.Children.Add(webView);
            await Task.Delay(15000);
            layoutRoot.Children.Remove(webView);
        }
开发者ID:jcorioland,项目名称:techdays-paris-2014-mvc-webapi,代码行数:19,代码来源:MainPage.xaml.cs

示例3: RefreshCookies

 public void RefreshCookies()
 {
     LoggingService.Log("Attempting at refreshing cookies", LoggingLevel.Verbose);
     if (Window.Current == null)
         return;
     Account account = AccountManager.GetAccount();
     if (account != null)
     {
         var loginUri = new Uri(account.LoginUrl);
         var instanceUri = new Uri(account.InstanceUrl);
         var filter = new HttpBaseProtocolFilter();
         var cookie = new HttpCookie("salesforce", loginUri.Host, "/");
         var instance = new HttpCookie("salesforceInstance", instanceUri.Host, "/");
         cookie.Value = account.AccessToken;
         instance.Value = account.AccessToken;
         filter.CookieManager.SetCookie(cookie, false);
         filter.CookieManager.SetCookie(instance, false);
         var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, instanceUri);
         var web = new WebView();
         web.NavigateWithHttpRequestMessage(httpRequestMessage);
     }
     LoggingService.Log("finished refreshing cookies", LoggingLevel.Verbose);
 }
开发者ID:maliroteh,项目名称:SalesforceMobileSDK-Windows,代码行数:23,代码来源:AuthHelper.cs

示例4: RefreshCookies

 public static void RefreshCookies()
 {
     PlatformAdapter.SendToCustomLogger("OAuth.RefreshCookies - attempting at refreshing cookies", LoggingLevel.Verbose);
     Account account = AccountManager.GetAccount();
     if (account != null)
     {
         var loginUri = new Uri(account.LoginUrl);
         var instanceUri = new Uri(account.InstanceUrl);
         var filter = new HttpBaseProtocolFilter();
         var cookie = new HttpCookie("salesforce", loginUri.Host, "/");
         var instance = new HttpCookie("salesforceInstance", instanceUri.Host, "/");
         cookie.Value = account.AccessToken;
         instance.Value = account.AccessToken;
         filter.CookieManager.SetCookie(cookie, false);
         filter.CookieManager.SetCookie(instance, false);
         var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, instanceUri);
         var web = new WebView();
         web.NavigateWithHttpRequestMessage(httpRequestMessage);
     }
     PlatformAdapter.SendToCustomLogger("OAuth.RefreshCookies - done", LoggingLevel.Verbose);
 }
开发者ID:jhsfdc,项目名称:SalesforceMobileSDK-Windows,代码行数:21,代码来源:OAuth2.cs


注:本文中的Windows.UI.Xaml.Controls.WebView.NavigateWithHttpRequestMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。