/// <summary>
        /// 设置参数到http请求内容
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="parameter">特性关联的参数</param>
        /// <exception cref="HttpApiConfigException"></exception>
        /// <returns></returns>
        protected override async Task SetHttpContentAsync(ApiActionContext context, ApiParameterDescriptor parameter)
        {
            var form        = parameter.ToString();
            var httpContent = await UrlEncodedContent.FromHttpContentAsync(context.RequestMessage.Content).ConfigureAwait(false);

            await httpContent.AddRawFormAsync(form).ConfigureAwait(false);

            context.RequestMessage.Content = httpContent;
        }
Example #2
0
        /// <summary>
        /// 请求Token
        /// </summary>
        /// <param name="credentials">身份信息</param>
        /// <returns></returns>
        private async Task <TokenResult> RequestTokenResultAsync(Credentials credentials)
        {
            var httpContent = new UrlEncodedContent();
            var keyValues   = keyValueFormatter.Serialize(null, credentials, this.FormatOptions);
            await httpContent.AddFormFieldAsync(keyValues).ConfigureAwait(false);

            using (var httpClient = new HttpClient {
                Timeout = this.timeout
            })
            {
                var response = await httpClient.PostAsync(this.TokenEndpoint, httpContent).ConfigureAwait(false);

                var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                var token = jsonFormatter.Deserialize(json, typeof(TokenResult));
                return(token as TokenResult);
            }
        }