/// <summary> /// Realiza a busca do endereço a partir do cep no site dos correios /// </summary> /// <param name="cep">Cep utilizado para busca</param> /// <returns>Address</returns> public static Address GetAddress(string cep) { var address = new Address(); address.Cep = cep; string url = "http://m.correios.com.br/movel/buscaCepConfirma.do"; string dataToPost = "cepEntrada=" + cep + "&tipoCep=&cepTemp=&metodo=buscarCep"; string method = "POST"; string contentType = "application/x-www-form-urlencoded"; Correios.Net.Http.Request request = new Correios.Net.Http.Request(url, dataToPost, method, contentType); Correios.Net.Http.Response response = request.Send(); return response.ToAddress(); }
public void BuscaCep(string cep) { address = SearchZip.GetAddress(cep); if (address.Street != "Não encontrado") { Encontrou = true; Logradouro = address.Street; Uf = address.State; Municipio = address.City; Bairro = address.District; CepUnico = address.UniqueZip; } else { Encontrou = false; Logradouro = ""; Uf = ""; Municipio = ""; Bairro = ""; CepUnico = true; } }