Interface IFormData
- Namespace
- Microsoft.Playwright
- Assembly
- Microsoft.Playwright.dll
The IFormData is used create form data that is sent via IAPIRequestContext.
public interface IFormData
Methods
Append(string, FilePayload)
Appends a new value onto an existing key inside a FormData object, or adds the key
if it does not already exist. File values can be passed either as Path
or
as FilePayload
. Multiple fields with the same name can be added.
The difference between Set(string, string) and Append(string, string) is that if the specified key already exists, Set(string, string) will overwrite all existing values with the new one, whereas Append(string, string) will append the new value onto the end of the existing set of values.
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 });
IFormData Append(string name, FilePayload value)
Parameters
name
stringField name.
value
FilePayloadField value.
Returns
Append(string, bool)
Appends a new value onto an existing key inside a FormData object, or adds the key
if it does not already exist. File values can be passed either as Path
or
as FilePayload
. Multiple fields with the same name can be added.
The difference between Set(string, string) and Append(string, string) is that if the specified key already exists, Set(string, string) will overwrite all existing values with the new one, whereas Append(string, string) will append the new value onto the end of the existing set of values.
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 });
IFormData Append(string name, bool value)
Parameters
Returns
Append(string, int)
Appends a new value onto an existing key inside a FormData object, or adds the key
if it does not already exist. File values can be passed either as Path
or
as FilePayload
. Multiple fields with the same name can be added.
The difference between Set(string, string) and Append(string, string) is that if the specified key already exists, Set(string, string) will overwrite all existing values with the new one, whereas Append(string, string) will append the new value onto the end of the existing set of values.
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 });
IFormData Append(string name, int value)
Parameters
Returns
Append(string, string)
Appends a new value onto an existing key inside a FormData object, or adds the key
if it does not already exist. File values can be passed either as Path
or
as FilePayload
. Multiple fields with the same name can be added.
The difference between Set(string, string) and Append(string, string) is that if the specified key already exists, Set(string, string) will overwrite all existing values with the new one, whereas Append(string, string) will append the new value onto the end of the existing set of values.
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 });
IFormData Append(string name, string value)
Parameters
Returns
Set(string, FilePayload)
Sets a field on the form. File values can be passed either as Path
or as
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 });
IFormData Set(string name, FilePayload value)
Parameters
name
stringField name.
value
FilePayloadField value.
Returns
Set(string, bool)
Sets a field on the form. File values can be passed either as Path
or as
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 });
IFormData Set(string name, bool value)
Parameters
Returns
Set(string, int)
Sets a field on the form. File values can be passed either as Path
or as
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 });
IFormData Set(string name, int value)
Parameters
Returns
Set(string, string)
Sets a field on the form. File values can be passed either as Path
or as
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 });
IFormData Set(string name, string value)