/// <summary> /// 设置参数到http请求内容 /// </summary> /// <param name="context">上下文</param> /// <exception cref="ApiInvalidConfigException"></exception> /// <returns></returns> protected override async Task SetHttpContentAsync(ApiParameterContext context) { var form = context.ParameterValue?.ToString(); var fromContent = await FormContent.ParseAsync(context.HttpContext.RequestMessage.Content).ConfigureAwait(false); fromContent.AddForm(form); context.HttpContext.RequestMessage.Content = fromContent; }
/// <summary> /// 添加字段到已有的Content /// 要求content-type为application/x-www-form-urlencoded /// </summary> /// <param name="keyValues">键值对</param> /// <exception cref="NotSupportedException"></exception> /// <returns></returns> public override async Task AddFormFieldAsync(IEnumerable <KeyValue> keyValues) { this.EnsureMediaTypeEqual(FormContent.MediaType); var formContent = await FormContent.ParseAsync(this.Content).ConfigureAwait(false); formContent.AddFormField(keyValues); this.Content = formContent; }