G
G
Georgy Kuznetsov2022-01-20 19:50:51
CORS
Georgy Kuznetsov, 2022-01-20 19:50:51

How to properly write an axios request with a CORS header?

I wrote this code under axios to get elements from the backend in C # (ASP.NET), but the request is blocked with the justification that the request lacks the request header "No 'Access-Control-Allow-Origin' header is present on the requested resource" .

const BaseURL = "http://localhost:5142/api/";

// Получить все элементы меню
export default function GetAllNews() {
    let answer = []
    axios.get(BaseURL + "News/get-all")
        .then(response => {
            answer = response.data
        })
        .catch(e => console.log(e))
    return answer;
}


I also rummaged through the Internet in search of a solution to the problem, but everywhere they write that you just need to set the CORS policy in the backend, which I did, but the error did not disappear

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question