1
Hello, I’m having the following mistake:
No 'Access-Control-Allow-Origin' header is present on the requested Resource.
Already researched and the solution I find is to add:
request.setRequestHeader('Access-Control-Allow-Origin', '*');
However, even then the error persists. If I run the application with Cors turned off, it works normally. Can anyone help me?
var request = new XMLHttpRequest();
request.open('GET', 'https://www.URLAPI.com/api/v3/PARAMETRO);
request.setRequestHeader('Access-Control-Allow-Origin', '*');
request.setRequestHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
request.setRequestHeader('Access-Control-Allow-Headers', 'Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers');
request.setRequestHeader('Content-Type', 'application/json'); //Obrigatorio API
request.setRequestHeader('access_token', 'MEUTOKEN'); //Obrigatorio API
request.onreadystatechange = function () {
if (this.readyState === 4) {
if(request.status === 200){
console.log('Status:', this.status);
console.log('Headers:', this.getAllResponseHeaders());
console.log('Body:', this.responseText);
console.log(request);
}else{
console.log("Erro");
console.log(request);
}
}
};
request.send();
Angular Project 7 (WEB). I can only access the data I need when I run Chrome with CORS disabled.
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --disable-gpu --user-data-dir=~/chromeTemp
Have to release the CORS on the server, that’s where you changed?
– rnd_rss