I used Ract.js want to get data from webapi .net 8
I used in React like this:
headers: { "Access-Control-Allow-Origin": "*" },
};
axios.get("https://localhost:7226/Comment/GetAlLComment", config)
.then((response) => {
console.log("response", response);
})
.catch((error) => {
console.log("Error", error);
});
Now I get two Errors:
- localhost/:1 Access to XMLHttpRequest at ‘https://localhost:7226/Comment/GetAlLComment’ 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.
- “AxiosError: Network Errorn at XMLHttpRequest.handleError (http://localhost:3000/static/js/bundle.js:42431:14)n at Axios.request (http://localhost:3000/static/js/bundle.js:42883:41)”
I get whitout erro in other URL like: “https://jsonplaceholder.typicode.com/comments”
4