本文整理汇总了C#中HttpClient.ExecuteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.ExecuteAsync方法的具体用法?C# HttpClient.ExecuteAsync怎么用?C# HttpClient.ExecuteAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient.ExecuteAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RequestToken
public Task<OAuthResponse> RequestToken(string code)
{
HttpClient client = new HttpClient { BaseAddress = new Uri(_config.OAuthURI) };
var request = new HttpRequestMessage(HttpMethod.Post, "access_token");
request.AddParameter("client_id", _config.ClientId);
request.AddParameter("client_secret", _config.ClientSecret);
request.AddParameter("grant_type", "authorization_code");
request.AddParameter("redirect_uri", _config.RedirectURI);
request.AddParameter("code", code);
return client.ExecuteAsync<OAuthResponse>(request);
}
示例2: RequestToken
public Task<OAuthResponse> RequestToken(string code)
{
HttpClient client = new HttpClient { BaseAddress = new Uri(config.OAuthUri) };
var request = new HttpRequestMessage(HttpMethod.Post, new Uri(client.BaseAddress, "access_token"));
//HttpClient client = new HttpClient();
//var request = new HttpRequestMessage(HttpMethod.Post, "https://api.instagram.com/oauth/access_token");
string myParameters = string.Format("client_id={0}&client_secret={1}&grant_type={2}&redirect_uri={3}&code={4}",
config.ClientId.UrlEncode(),
config.ClientSecret.UrlEncode(),
"authorization_code".UrlEncode(),
config.RedirectUri.UrlEncode(),
code.UrlEncode());
request.Content = new StringContent(myParameters);
return client.ExecuteAsync<OAuthResponse>(request);
}
示例3: RequestToken
/// <summary>
/// Requests the token.
/// </summary>
/// <param name="code">The code.</param>
/// <returns>An OAuthResponse object</returns>
public Task<OAuthResponse> RequestToken(string code)
{
var client = new HttpClient { BaseAddress = new Uri(config.OAuthUri) };
var request = new HttpRequestMessage(HttpMethod.Post, new Uri(client.BaseAddress, "access_token"));
var multipartFormDataContent = new MultipartFormDataContent
{
{new StringContent(config.ClientId), "client_id"},
{new StringContent(config.ClientSecret), "client_secret"},
{new StringContent("authorization_code"), "grant_type"},
{new StringContent(config.RedirectUri), "redirect_uri"},
{new StringContent(code), "code"},
};
request.Content = multipartFormDataContent;
return client.ExecuteAsync<OAuthResponse>(request);
}