I have a database of users on Azure and I’m trying to call POST from my React app. But every time i try it, I get this error: Access to XMLHttpRequest at ‘https://stin-backend-apimanag.azure-api.net/api/Users’ from origin ‘http://localhost:3000’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
Here is how I´m calling POST from my React app:
try {
const response = await axios.post('https://stin-backend-apimanag.azure-api.net/api/Users', {
username: usernameInput.value,
password: passwordInput.value,
pay: "no"
});
setHead(payment);
setFavorites("---");
} catch (error) {
console.error('Chyba při vytváření uživatele:', error);
alert('Došlo k chybě při vytváření uživatele. Zkuste to prosím znovu.');
}
In CORS settings, I have already put *, but it didn’t help. The weird thing for me is, that GET is working with no problems, but POST is throwing me an error.
Jan Sodomka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.