2
I am trying to get the delivery time dynamically using the Webservice Post, for this I am using this documentation.
If you enter the their test page, it is possible to enter the PAC service, for example, 4510
and the source and destination ceps to get the return on an XML page.
I found that this form makes a simple POST by copying it to my localhost. But by trying to do it without the form, but by using curl
did not succeed.
My code so far is:
$data['nCdServico'] = '4510';
$data['sCepOrigem'] = '36572008';
$data['sCepDestino'] = '36700000';
$url = 'http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx/CalcPrazo';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$resp = curl_exec($ch);
curl_close($ch);
var_dump($resp);exit;
But the return is false
I would like a help to know what I’m forgetting so that the return is the data of the sending deadline and not just the boolean false.
Why aren’t you wearing
SoapClient
?– Gabriel Heming
Just lack of knowledge on how to use it.
– David Alves
That’s a good argument, I’ll write an answer
– Gabriel Heming
Whoa, I was having lunch, I’ll check in there. Thanks.
– David Alves