Alex BourgOriginal post
Rank 1: Thread
Hi, when I send a request using js to my function, the request method changes from POST to OPTIONS. It works as POST on postman, or python script, but not when I use js.. anyone seen this before?
fetch(apiUrl, {
method: 'POST',
headers: myHeaders,
body: JSON.stringify(data),
redirect: "follow"
// body: JSON.stringify({
// data: JSON.stringify(data), // Data needs to be a string inside the outer JSON payload
// async: false
// })
})
I tried the 2 approaches above..
Summary
When sending a POST request from JS to a function, the request method changes to OPTIONS due to browsers making a preflight CORS check. This behavior is expected. You can adjust your server to handle OPTIONS requests or use a proxy to forward the requests.