Headers can be assigned to a fetch request using the Headers constructor and the fetch API:
const myHeaders = new Headers();
myHeaders.append('Content-Type', 'application/json');
fetch('https://example.com', {
method: 'POST',
headers: myHeaders,
body: JSON.stringify({ key: 'value' })
})
.then(response => {
// handle response
})
.catch(error => {
// handle error
});
Asked: 2021-08-05 11:00:00 +0000
Seen: 7 times
Last updated: Mar 08 '23