[HttpPost("upload")]
public async Task
using System.Net.Http; using System.Net.Http.Headers;
var client = new HttpClient(); var content = new MultipartFormDataContent();
// 添加文件 foreach(var file in files) { var fileContent = new StreamContent(file.OpenReadStream()); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = file.FileName }; content.Add(fileContent, "files", file.FileName); }
// 添加其他参数 content.Add(new StringContent(param1), "param1"); content.Add(new StringContent(param2.ToString()), "param2");
// 发送请求 var response = await client.PostAsync("https://example.com/api/upload", content);
注意事项: