要将multipart/form-data发送到Power Automate,您可以使用ASP.NET的HttpClient类来发送HTTP请求。以下是一个示例代码,演示了如何使用HttpClient类将multipart/form-data发送到Power Automate:
using System;
using System.Net.Http;
using System.Threading.Tasks;
public class Program
{
public static async Task Main(string[] args)
{
using (var httpClient = new HttpClient())
{
// 设置Power Automate的URL
var url = "https://your-flow-url";
// 创建一个MultipartFormDataContent对象
var formDataContent = new MultipartFormDataContent();
// 添加要上传的文件
var fileContent = new ByteArrayContent(System.IO.File.ReadAllBytes("path/to/your/file"));
formDataContent.Add(fileContent, "file", "filename.txt");
// 添加其他表单字段
formDataContent.Add(new StringContent("value1"), "field1");
formDataContent.Add(new StringContent("value2"), "field2");
// 发送POST请求
var response = await httpClient.PostAsync(url, formDataContent);
// 检查响应状态码
if (response.IsSuccessStatusCode)
{
Console.WriteLine("上传成功");
}
else
{
Console.WriteLine("上传失败");
}
}
}
}
请确保替换示例代码中的"url"为您的实际Power Automate URL,"path/to/your/file"为您要上传的文件的实际路径,"field1"和"field2"为您的表单字段名称,"value1"和"value2"为您要发送的表单字段值。
运行此代码将发送一个包含文件和其他表单字段的multipart/form-data请求到Power Automate。您可以根据Power Automate的处理逻辑自定义响应处理部分。