2
I am trying to make a request for freight calculation for the post office, but when I request the request, returns the error error of CORS --
Error message:
Access to XMLHttpRequest at 'http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx/CalcPrecoPrazo?nCdEmpresa=&sDsSenha=&nCdServico=4510&sCepOrigem=72001835&sCepDestino=75180000&nVlPeso=1&nCdFormato=1&nVlComprimento=16&nVlAltura=5&nVlLargura=15&nVlDiametro=0&sCdMaoPropria=n&nVlValorDeclarado=100&sCdAvisoRecebimento=n' from origin 'http://localhost:4200' 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.
Call code:
testeCorreios(){
let url = 'http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx/CalcPrecoPrazo';
//let h = new HttpHeaders()
//.append('Access-Control-Allow-Credentials', 'true')
//.append('Access-Control-Allow-Methods', '*')
//.append('Access-Control-Allow-Origin', '*');
let p = new HttpParams()
.set('nCdEmpresa', '')
.set('sDsSenha', '')
.set('nCdServico', '4510')
.set('sCepOrigem', '72001835')
.set('sCepDestino', '75180000')
.set('nVlPeso', '1')
.set('nCdFormato', '1')
.set('nVlComprimento', '16')
.set('nVlAltura', '5')
.set('nVlLargura', '15')
.set('nVlDiametro', '0')
.set('sCdMaoPropria', 'n')
.set('nVlValorDeclarado', '100')
.set('sCdAvisoRecebimento', 'n');
return this.http.get(url, {
headers: h,
responseType: 'text',
params: p
});
}
I tried to add a header and stuff, but it didn’t work. For testing I was using a Chrome plugin to pass, but when I go to production it does not work (until pq is not with the plugin). Somebody help me out there
It did not work friend, still gives the error of Cors. But thanks for the attempt. I think what needs to be done is to add something in the header to give access and such
– mGois