You can send data with the application/x-www-form-urlencoded
content type (the one that encodes values similar to a query string, e.g. first=1&second=2
) using a URLSearchParams
object, like so:
fetch(url, {
method: "POST",
body: new URLSearchParams({first: 1, second: 2})
});
method: "POST",
body: new URLSearchParams({first: 1, second: 2})
});
Other formats are explained in the Mozilla docs.