本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
}