private static byte[] GetBytes(object content, Encoding encoding, IFormDataFormatter formatter) { if (content is null) { return(EmptyContent); } else if (content is string str) { return(GetBytes(str, encoding)); } var data = string.Empty; if (string.IsNullOrEmpty(data)) { data = formatter.Format(content, new(true)); } return(encoding.GetBytes(data)); }
/// <inheritdoc cref="FormContent(object, string, Encoding, IFormDataFormatter)"/> public FormContent(object content, IFormDataFormatter formatter) : this(content, ContentType, Encoding.UTF8, formatter) { }
/// <summary> /// HttpFormContent /// </summary> /// <param name="content">用于转换为form的对象</param> /// <param name="contentType">指定ContentType</param> /// <param name="encoding">指定编码类型</param> /// <param name="formatter">指定格式化器</param> public FormContent(object content, string contentType, Encoding encoding, IFormDataFormatter formatter) : base(GetBytes(content, encoding, formatter)) { Headers.TryAddWithoutValidation(HttpHeaderDefinitions.ContentType, contentType); }
public void Init() { _formatter = InitFormatter(); }