Does anyone know how to add or create a custom HTTP header using JavaScript or jQuery?
You can use js fetch
async function send(url,data) {
let r= await fetch(url, {
method: "POST",
headers: {
"My-header": "abc"
},
body: JSON.stringify(data),
})
return await r.json()
}
// Example usage
let url='https://server.test-cors.org/server?enable=true&status=200&methods=POST&headers=my-header';
async function run()
{
let jsonObj = await send(url,{ some: 'testdata' });
console.log(jsonObj[0].request.httpMethod + ' was send - open chrome console > network to see it');
}
run();