I’m trying to make a http query to a back-end,
i solved all the CORS issues, and it works fine when i do a GET query.
However, when i try POST, i get the following message :
'<!DOCTYPE html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot POST /</pre>\n</body>\n</html>\n'
Here is my code
const response = fetch('http://localhost:1337', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(inputData)
})
.then(result => {
console.log(result.text());
console.log(result);
});
Things i have tried :
- Make the query from the UI code (i already know that the environment in the UI is less sandboxed than the back-end, but it doesn’t change anything)
- use TextEncoder.encode on the body (as recommended by Palash here
Error making a POST request in a create-figma-plugin codebase - #2 by Palash) - use FormData instead of sending a JSON
I’ve seen a bunch of unresolved issue posted around that topic,
It seems quite unclear for a lot of people, it would be nice if the documentation could go more in depth (not just showing a GET example for example), i think a lot of people might be struggling with that.
Thanks in advance for the help.