1
I am trying to access the mail api to calculate freight and get the following msg:
Failed to load
http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx/CalcPrecoPrazo: No
'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://site.com' is therefore not allowed access.
my ajax:
var params = {
'nCdEmpresa': '',
'sDsSenha': '',
'nCdServico': '04014',
'sCepOrigem': '03638010',
'sCepDestino': '43810040',
'nVlPeso': '1',
'nCdFormato': '1',
'nVlComprimento': '16',
'nVlAltura': '5',
'nVlLargura': '15',
'nVlDiametro': '0',
'sCdMaoPropria': 'n',
'nVlValorDeclarado': '0',
'sCdAvisoRecebimento': 'n',
'StrRetorno': 'xml',
'nCdServico': '40010,41106'
};
$.ajax({
type: "POST",
url: "http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx/CalcPrecoPrazo",
data: params,
dataType : "xml",
success: function (data) {
console.log(JSON.stringify(data));
}
});
The browser blocks due Cors, to make it work a gambiarra (reverse proxy)
– Valdeir Psr
@Valdeirpsr how to do ajax with reverse proxy ?
– Alan PS
Depends on your server. If so Nginx: https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
– Valdeir Psr
Are you the owner of the consuming API? To release CORS, you must have access to the "back-end" API.
– Luiz Felipe
I think this link will help you a lot https://blog.garstasio.com/you-dont-need-jquery/ajax/#Cors
– MoshMage