예제 #1
0
        /// <summary>
        /// http请求之前
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="parameter">特性关联的参数</param>
        /// <returns></returns>
        async Task IApiParameterAttribute.BeforeRequestAsync(ApiActionContext context, ApiParameterDescriptor parameter)
        {
            var stringValue = parameter.Value == null ? null : parameter.Value.ToString();
            var keyValue    = new KeyValuePair <string, string>(parameter.Name, stringValue);
            var httpContent = await context.EnsureNoGet().RequestMessage.Content.MergeKeyValuesAsync(new[] { keyValue });

            context.RequestMessage.Content = httpContent;
        }
예제 #2
0
        /// <summary>
        /// http请求之前
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="parameter">特性关联的参数</param>
        /// <returns></returns>
        async Task IApiParameterAttribute.BeforeRequestAsync(ApiActionContext context, ApiParameterDescriptor parameter)
        {
            var stringValue = parameter.Value == null ? null : parameter.Value.ToString();
            var httpContent = context.EnsureNoGet().RequestMessage.Content.CastOrCreateMultipartContent();

            httpContent.AddText(parameter.Name, stringValue);
            context.RequestMessage.Content = httpContent;

            await TaskExtend.CompletedTask;
        }
예제 #3
0
        /// <summary>
        /// 执行前
        /// </summary>
        /// <param name="context">上下文</param>
        /// <returns></returns>
        public override async Task BeforeRequestAsync(ApiActionContext context)
        {
            if (string.IsNullOrEmpty(this.name))
            {
                throw new NotSupportedException("请传入name和value参数:" + this.GetType().Name);
            }

            var keyValue    = new KeyValuePair <string, string>(this.name, this.value);
            var httpContent = await context.EnsureNoGet().RequestMessage.Content.MergeKeyValuesAsync(new[] { keyValue });

            context.RequestMessage.Content = httpContent;
        }
예제 #4
0
        /// <summary>
        /// 执行前
        /// </summary>
        /// <param name="context">上下文</param>
        /// <returns></returns>
        public override async Task BeforeRequestAsync(ApiActionContext context)
        {
            if (string.IsNullOrEmpty(this.name))
            {
                throw new NotSupportedException("请传入name和value参数:" + this.GetType().Name);
            }

            var httpContent = context.EnsureNoGet().RequestMessage.Content.CastOrCreateMultipartContent();

            httpContent.AddText(this.name, this.value);
            context.RequestMessage.Content = httpContent;

            await TaskExtend.CompletedTask;
        }
 /// <summary>
 /// http请求之前
 /// </summary>
 /// <param name="context">上下文</param>
 /// <param name="parameter">特性关联的参数</param>
 /// <returns></returns>
 async Task IApiParameterAttribute.BeforeRequestAsync(ApiActionContext context, ApiParameterDescriptor parameter)
 {
     context.RequestMessage.Content = await this.GenerateHttpContentAsync(context.EnsureNoGet(), parameter);
 }