48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.IO;
|
|
using System.Net;
|
|
namespace IBRCAD
|
|
{
|
|
public class buscarCNPJ
|
|
{
|
|
string cnpj = "60872504000123"; // Substitua pelo CNPJ desejado
|
|
|
|
public static void ConsultarCNPJ(string cnpj)
|
|
{
|
|
try
|
|
{
|
|
string url = "http://www.receita.fazenda.gov.br/pessoajuridica/cnpj/cnpjreva/valida.asp";
|
|
string postData = $"origem=comprovante&cnpj={cnpj}&submit1=Consultar&search_type=cnpj";
|
|
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
|
request.Method = "POST";
|
|
request.ContentType = "application/x-www-form-urlencoded";
|
|
request.ContentLength = postData.Length;
|
|
|
|
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
|
|
{
|
|
writer.Write(postData);
|
|
}
|
|
|
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
|
|
{
|
|
string result = reader.ReadToEnd();
|
|
// Aqui você pode processar o resultado (web scraping) para obter as informações desejadas do CNPJ
|
|
Console.WriteLine(result);
|
|
MessageBox.Show(result);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Erro ao consultar CNPJ: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|