first of all: I already found similar problems to mine, but due to the fact that I am an absolute beginner in react and javascript, I was not able to both fully understand and solve my problem with the given tips and explanations.
My Problem: I want to make a fetch request via a given api (not mine), but get the CORS error written above, when I want to include the "Language" header. It appears that I am not allowed to make this request - the preflight response in the browser also shows that. Interesting part is: I get an response, if I make a Curl -X get request with the neccessary header in the command window.
So my question is: why am I allowed to make that request in the command window, but not in the browser? Is there any workaround or do I need to make some setting changes for chrome?`
JFYI, my Code - doesn´t work:
export const Items = () => {
fetch("https://requestedurl", {
headers: {
Accept: "application/json",
Language: "de",
},
}).then((res) => res.json())
.then((res) => console.log(res));
};
Works in command prompt:
curl -X GET -H "Language: de" https://requestedurl
Thanks for your help :)