/// <summary> /// 添加文件内容到已有的Content /// 要求content-type为multipart/form-data /// </summary> /// <param name="stream">文件流</param> /// <param name="name">名称</param> /// <param name="fileName">文件名</param> /// <param name="contentType">文件Mime</param> /// <exception cref="NotSupportedException"></exception> public void AddFormDataFile(Stream stream, string name, string fileName, string contentType) { this.EnsureNotGetOrHead(); var httpContent = this.CastToFormDataContent(); var fileContent = new FormDataFileContent(stream, name, fileName, contentType); httpContent.Add(fileContent); this.Content = httpContent; }
/// <summary> /// 添加文件内容到已有的Content /// 要求content-type为multipart/form-data /// </summary> /// <param name="stream">文件流</param> /// <param name="name">名称</param> /// <param name="fileName">文件名</param> /// <param name="contentType">文件Mime</param> /// <exception cref="NotSupportedException"></exception> public void AddFormDataFile(Stream stream, string name, string?fileName, string?contentType) { this.EnsureMediaTypeEqual(FormDataContent.MediaType); if (!(this.Content is MultipartContent httpContent)) { httpContent = new FormDataContent(); } var fileContent = new FormDataFileContent(stream, name, fileName, contentType); httpContent.Add(fileContent); this.Content = httpContent; }
/// <summary> /// 省略内容的文件请求内容 /// </summary> /// <param name="fileContent">文件内容</param> public EllipsisContent(FormDataFileContent fileContent) : base(content) { this.Headers.ContentDisposition = fileContent.Headers.ContentDisposition; this.Headers.ContentType = fileContent.Headers.ContentType; }