0
I have a routine to access the webservice of the post office that uses simplexml_load_file, but if for some reason the site of the post office is out of air or if it takes too long to answer my site returns an error, then I would like to treat this simplexml_load_file loading error, so that I can present a custom message to the user, tried in some ways more unsuccessfully, follow my current code:
$url = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?";
$url .= "nCdEmpresa=" . $cod_administrativo;
$url .= "&sDsSenha=" . $senha;
$url .= "&sCepOrigem=" . $cep_origem;
$url .= "&sCepDestino=" . $cep_destino;
$url .= "&nVlPeso=" . $peso;
$url .= "&nVlLargura=" . $largura;
$url .= "&nVlAltura=" . $altura;
$url .= "&nCdFormato=1";
$url .= "&nVlComprimento=" . $comprimento;
$url .= "&sCdMaoPropria=" . $mao_propria;
$url .= "&nVlValorDeclarado=" . $valor;
$url .= "&sCdAvisoRecebimento=" . $aviso_recebimento;
$url .= "&nCdServico=" . $servico;
$url .= "&nVlDiametro=0";
$url .= "&StrRetorno=xml";
$xml = simplexml_load_file($url);
if ($xml === false || $xml === 0 || $xml === "") {
return '';
}
return $xml->cServico;
Nothing yet, I did as you said and the error still continues
– Alexandre