[Vuejs]-How to solve net::ERR_CONNECTION_REFUSED or net::ERR_CONNECTION_RESET in axios?

0๐Ÿ‘

โœ…

We get a CORS Policy Error because we have these default headers in our bootstrap.js

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

You should remove default headers for one request in axios. You can use the transformRequest in the request you are making:

axios.get('xxxx.com', { transformRequest: [(data, headers) => {
   delete headers.common['X-Requested-With'];
   return data 
}] })
.then((response) => {
   console.log(response);
})

Leave a comment