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


C# HttpClient.ExecuteAsync方法代码示例

本文整理汇总了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);
        }
开发者ID:2RoN4eG,项目名称:InstaSharp,代码行数:13,代码来源:OAuth.cs

示例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);

        }
开发者ID:happynik,项目名称:InstaSharp,代码行数:18,代码来源:OAuth.cs

示例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);
        }
开发者ID:jooooel,项目名称:InstaSharp,代码行数:22,代码来源:OAuth.cs


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