4
I’m trying an implementation in php
via simplexml_load_file
for verification and return of data together with the Post API. In this case, it is necessary to pass variables in the url
. I’m doing like this:
I’m doing like this:
function encontraCep() {
$cep = $_POST["txtCep"];
$url = "https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl&txtCep=".$cep;
$xml = simplexml_load_file($url);
return $xml;
}
dados = encontraCep();
a simple
print "<pre>";
print_r($dados);
print "</pre>";
Call me back:
SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => AtendeClienteService
[targetNamespace] => http://cliente.bean.master.sigep.bsb.correios.com.br/
)
)
Where am I going wrong?
I’m following the tutorial given in http://www.eduardorizo.com.br/2014/12/04/correios-webservice-para-consulta-de-enderecos-a-partir-de-um-cep/, made in Asp.net
There he makes a form:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Teste WS dos Correios</h1><br />
<asp:Panel ID="Panel1" runat="server" GroupingText="Busca Endereço">
CEP:
<asp:TextBox ID="txtCep" runat="server"></asp:TextBox>&nbsp;<asp:Button ID="btnBuscarEndereco" runat="server" OnClick="btnBuscarEndereco_Click" Text="Buscar Endereço" />
<br />
<asp:Label ID="lblEndereco" runat="server"></asp:Label>
</asp:Panel>
</div>
</form>
</body>
</html>
And a function that picks up the return:
protected void btnBuscarEndereco_Click(object sender, EventArgs e)
{
wsCorreio.AtendeClienteClient ws = new wsCorreio.AtendeClienteClient("AtendeClientePort"); //Verificar o nome do endpoint no arquivo Web.config
var dados = ws.consultaCEP(txtCep.Text);
if (dados != null)
{
lblEndereco.Text = string.Format(@"Endereço: {0}<br />
Complemento 1: {1}<br />
Complemento 2: {2}<br />
Bairro: {3}<br />
Cidade: {4}<br />
Estado: {5}",
dados.end,
dados.complemento,
dados.complemento2,
dados.bairro,
dados.cidade,
dados.uf);
}
else
lblEndereco.Text = "CEP não encontrado.";
}
But there is no action
in the form
of him to see the sending of url
.
error on this line: $cep = $client->query CEP(['cep' =>'01415000']);
– Carlos Rocha
what mistake? @Carlosrocha
– user46523
I arranged asim $cepC = array ('cep'=>'36880000'); $cep = $client->query CEP($cepC);. But it tells me 2 things: does this return not inform error codes? Why do you say that this web service is too slow? Do you use another one? In fact, what happens is that in the store, as soon as the customer puts the zip code, it goes to an address form page, and then it goes to the freight calculation page. I’m not finding a webservice that returns price and term and also address data
– Carlos Rocha
It must be the version of your php because of the error, but I already fix blz. If the cep is not found it informs yes type a invalid cep. The webservice takes time to answer in PHP already in . Net is normal that I do not know and yes the post office. I use (viacep.com.br)[viacep.com.br]
– user46523
But it does not return error code this request. Instead, it gives error in SOAP. That’s right?
– Carlos Rocha
Another thing: viacep is safe?
– Carlos Rocha
The viacep.com.br is an alternative that never left me in the lurch. I made an edition in the reply, Observer and use in the best possible way.
– user46523
thank you very much. Thank you very much!
– Carlos Rocha
stopped working this script. Add in your reply the vi cep implementation doing favor
– Carlos Rocha
added in another reply!
– user46523