-2
Today I can consume Cadsus Aces by dotnet c#. However, now I need to consume these same Apis(cadsus) via javascript(screen), but, I’m getting the following error when I make the following request via browser:
Access to XMLHttpRequest at 'https://servicos.saude.gov.br/' from origin 'http://localhost:4566' 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.
POST https://servicos.saude.gov.br/ net::ERR_FAILED
Somebody’s been through this trouble and they know how to fix it?
my code is as follows:
<script>
function soap() {
var xmlhttp = new XMLHttpRequest();
var url = $('#url').val();
var SOAPEnvelope = $('#SOAPEnvelope').val();
xmlhttp.open('POST', url, true);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
alert(xmlhttp.responseText);
}
}
}
xmlhttp.setRequestHeader('SOAPAction', 'https://servicos.saude.gov.br/cadsus/PDQSupplier');
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(SOAPEnvelope);
}
</script>
Related: What is the meaning of CORS?
– Icaro Martins
Related: CORS - No 'Access-Control-Allow-Origin' header is present on the requested Resource
– Icaro Martins