/// <summary>
        /// 设置参数到http请求内容
        /// </summary>
        /// <param name="context">上下文</param>
        /// <returns></returns>
        protected override Task SetHttpContentAsync(ApiParameterContext context)
        {
            var keyValues = context.SerializeToKeyValues().CollectAs(this.CollectionFormat);

            context.HttpContext.RequestMessage.AddFormDataText(keyValues);
            return(Task.CompletedTask);
        }
Example #2
0
 /// <summary>
 /// http请求之前
 /// </summary>
 /// <param name="context">上下文</param>
 /// <exception cref="ApiInvalidConfigException"></exception>
 /// <returns></returns>
 public override Task OnRequestAsync(ApiParameterContext context)
 {
     foreach (var item in context.SerializeToKeyValues())
     {
         if (string.IsNullOrEmpty(item.Value) == false)
         {
             var name = this.UnderlineToMinus ? item.Key.Replace("_", "-") : item.Key;
             context.HttpContext.RequestMessage.Headers.TryAddWithoutValidation(name, item.Value);
         }
     }
     return(Task.CompletedTask);
 }
Example #3
0
        /// <summary>
        /// http请求之前
        /// </summary>
        /// <param name="context">上下文</param>
        /// <exception cref="ApiInvalidConfigException"></exception>
        /// <returns></returns>
        public override Task OnRequestAsync(ApiParameterContext context)
        {
            var uri = context.HttpContext.RequestMessage.RequestUri;

            if (uri == null)
            {
                throw new ApiInvalidConfigException(Resx.required_HttpHost);
            }

            var keyValues = context.SerializeToKeyValues().CollectAs(this.CollectionFormat);

            context.HttpContext.RequestMessage.RequestUri = this.CreateUri(uri, keyValues);
            return(Task.CompletedTask);
        }
Example #4
0
        /// <summary>
        /// http请求之前
        /// </summary>
        /// <param name="context">上下文</param>
        /// <exception cref="ApiInvalidConfigException"></exception>
        /// <returns></returns>
        public override Task OnRequestAsync(ApiParameterContext context)
        {
            var keyValues = context.SerializeToKeyValues();

            foreach (var kv in keyValues)
            {
                var value = kv.Value;
                if (value != null)
                {
                    var name = this.UnderlineToMinus ? kv.Key.Replace("_", "-") : kv.Key;
                    context.HttpContext.RequestMessage.Headers.TryAddWithoutValidation(name, value);
                }
            }
            return(Task.CompletedTask);
        }
 /// <summary>
 /// 序列化参数为keyValue
 /// </summary>
 /// <param name="context">上下文</param>
 /// <returns></returns>
 protected virtual IEnumerable <KeyValue> SerializeToKeyValues(ApiParameterContext context)
 {
     return(context.SerializeToKeyValues());
 }
 /// <summary>
 /// 序列化参数为keyValue
 /// </summary>
 /// <param name="context">上下文</param>
 /// <returns></returns>
 protected virtual IEnumerable <KeyValue> SerializeToKeyValues(ApiParameterContext context)
 {
     return(context.SerializeToKeyValues().CollectAs(this.CollectionFormat));
 }
Example #7
0
 /// <summary>
 /// 设置参数到http请求内容
 /// </summary>
 /// <param name="context">上下文</param>
 protected override async Task SetHttpContentAsync(ApiParameterContext context)
 {
     var keyValues = context.SerializeToKeyValues().CollectAs(this.CollectionFormat);
     await context.HttpContext.RequestMessage.AddFormFieldAsync(keyValues).ConfigureAwait(false);
 }