Vue and Axios CORS error No 'Access-Control-Allow-Origin' header is present on the requested resource
34,848
baseURL: 'https://www.yourserver.com.br',
timeout: 10000,
withCredentials: false
setting axios.defaults.withCredentials = true;
Author by
James Parsons
Updated on July 09, 2022Comments
-
James Parsons almost 2 years
I am currently getting the above error, I am using Axios to make the GET request to an external API. After reading the Mozilla docs, doing a lot of research and trying different options I am still not any better off.
I have stripped the code back to the basics:
axios.get('URL.com', { headers: { Access-Control-Allow-Origin: * }, auth: { username: 'username', password: 'password' }, }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
Do I need to add anything else to the headers?
Everything works through Postman so once I can pass the CORS issue everything will work.
-
New Alexandria over 6 yearsGreetings. A proper answer here involves more explanation than just the code. Can you say a bit more about your intent?
-
yivi over 6 yearsWhile this code snippet may be the solution, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.