fetchCorreiosService function
Implementation
Future<Cep> fetchCorreiosService(String cepWithLeftPad) async {
final url = Uri.parse(
'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente');
Cep resposta = const Cep();
final response = await http.post(
url,
headers: {
'Content-Type': 'text/xml;charset=UTF-8',
'cache-control': 'no-cache',
},
body:
'<?xml version="1.0"?>\n<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">\n <soapenv:Header />\n <soapenv:Body>\n <cli:consultaCEP>\n <cep>$cepWithLeftPad</cep>\n </cli:consultaCEP>\n </soapenv:Body>\n</soapenv:Envelope>',
);
try {
final analyze = analyzeAndParseResponse(response);
if (analyze != null) resposta = extractValuesFromSuccessResponse(analyze);
} catch (e) {
throwApplicationError(e);
}
return resposta;
}