FormData
FormData 用于创建通过 APIRequestContext 发送的表单数据。
方法
追加
Added in: v1.44向FormData对象中的现有键追加一个新值,如果该键不存在则添加该键。文件值可以作为Path
或FilePayload
传递。可以添加多个同名字段。
FormData.Set()和FormData.Append()的区别在于,如果指定的键已存在,FormData.Set()会用新值覆盖所有现有值,而FormData.Append()会将新值追加到现有值集的末尾。
var multipart = Context.APIRequest.CreateFormData();
// Only name and value are set.
multipart.Append("firstName", "John");
// Name, value, filename and Content-Type are set.
multipart.Append("attachment", new FilePayload()
{
Name = "pic.jpg",
MimeType = "image/jpeg",
Buffer = File.ReadAllBytes("john.jpg")
});
// Name, value, filename and Content-Type are set.
multipart.Append("attachment", new FilePayload()
{
Name = "table.csv",
MimeType = "text/csv",
Buffer = File.ReadAllBytes("my-tble.csv")
});
await Page.APIRequest.PostAsync("https://localhost/submit", new() { Multipart = multipart });
用法
FormData.Append(name, value);
参数
返回
设置
Added in: v1.18设置表单上的字段。文件值可以作为Path
或FilePayload
传递。
var multipart = Context.APIRequest.CreateFormData();
// Only name and value are set.
multipart.Set("firstName", "John");
// Name, value, filename and Content-Type are set.
multipart.Set("profilePicture", new FilePayload()
{
Name = "john.jpg",
MimeType = "image/jpeg",
Buffer = File.ReadAllBytes("john.jpg")
});
multipart.Set("age", 30);
await Page.APIRequest.PostAsync("https://localhost/submit", new() { Multipart = multipart });
用法
FormData.Set(name, value);
参数
返回