CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Hi everyone,
I'm trying to make a connection with the internal Intranet system.
If I enable "Moesif CORS extension" for google chrome I'm able to send a POST to the server and this one answer with a positive message.
So, the code that I used is similar to this one:
$scope.authServices = function() {
var xhttp = new XMLHttpRequest();
var url = ''
var url_home= 'http://localhost:3000/resource/test_API_auth_001/dist/index-desktop.html#/Home'
//xhttp.setRequestHeader("Content-Type", "application/json");
//xhttp.setRequestHeader("Access-Control-Request-Method", "POST");
//xhttp.setRequestHeader("appKey", "xxxxxx");
//xhttp.setRequestHeader("Accept", "application/json");
xhttp.open('POST', url, false);
xhttp.setRequestHeader("Access-Control-Allow-Origin", url_home);
xhttp.onload = function () {
if (xhttp.readyState === xhttp.DONE) {
if (xhttp.status === 200) {
console.log(xhttp.response);
console.log(xhttp.responseText);
$scope.app.params['ServiceResult'] = xhttp.responseText;
text="---ok---"
$scope.setWidgetProp( "authService", "text", text)
}
else{
text="---ERR---"
$scope.setWidgetProp( "authService", "text", text)
}
}
};
xhttp.send("{'username': 'xxxxxx', 'password': 'yyyyyyyy'}");
}
$scope.authServices();
The answer of the chrome console is:
Access to XMLHttpRequest at 'http://intranet.xyz.it/i/api_auth_for_services.php' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Anyone has a solutions?

