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.
If the server is under your control, add the origin of the requesting site to the set of domains permitted access by adding it to the Access-Control-Allow-Origin header's value. You can also configure a site to allow any site to access it by using the * wildcard. You should only use this for public APIs.
You can set a proxy in Vue using the vue. The file is located on the root directory of a Vue project. If it's not present, you can create one. Not every fix for a CORS error is a good fix. For example, setting the value for the Access-Control-Allow-Origin header to " * " on the back end may clear many CORS errors.
baseURL: 'https://www.yourserver.com.br',
timeout: 10000,
withCredentials: false
setting axios.defaults.withCredentials = true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With