Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validar RNC #9

Open
DiomedesDominguez opened this issue Dec 13, 2018 · 0 comments
Open

Validar RNC #9

DiomedesDominguez opened this issue Dec 13, 2018 · 0 comments

Comments

@DiomedesDominguez
Copy link

 public bool IsRNCValid(string rnc)
        {
            HttpWebRequest webrequest =
                   (HttpWebRequest)WebRequest.Create("https://dgii.gov.do/app/WebApps/ConsultasWeb/consultas/rnc.aspx");

            webrequest.Method = "POST";
            webrequest.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
            webrequest.Headers.Add("Origin", "https://dgii.gov.do");
            webrequest.Referer = "https://dgii.gov.do/app/WebApps/ConsultasWeb/consultas/rnc.aspx";
            webrequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134";
            webrequest.Headers.Add("X-MicrosoftAjax", "Delta=true");
            webrequest.Headers.Add("Cache-Control", "no-cache");
            webrequest.Accept = "*/*";
            webrequest.Headers.Add("Accept-Language", "en-US,en;q=0.8,es-US;q=0.5,es;q=0.3");
            webrequest.Headers.Add("Accept-Encoding", "gzip, deflate, br");
            webrequest.KeepAlive = true;
            webrequest.Headers.Add("Cookie", "_ga=GA1.3.1057587116.1543410096; NSC_EHJJ_efgbvmu_mcwt=ffffffffc3a0e53e45525d5f4f58455e445a4a423660; _gid=GA1.3.199539022.1544729351; _gat=1; NSC_EHJJ_TTM_BQQ_MCWT=ffffffffc3a0e52245525d5f4f58455e445a4a42378b");

            webrequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            string postData = $"ctl00%24smMain=ctl00%24cphMain%24upBusqueda%7Cctl00%24cphMain%24btnBuscarPorRNC&ctl00%24cphMain%24txtRNCCedula={rnc}&ctl00%24cphMain%24txtRazonSocial=&__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKMTkxNDA2Nzc4Nw9kFgJmD2QWAgIBD2QWAgIDD2QWAmYPZBYCAgEPZBYEAgEPDxYIHgRUZXh0BTpObyBzZSBlbmNvbnRyYXJvbiBkYXRvcyByZWdpc3RyYWRvcyBkZSBlc3RlIGNvbnRyaWJ1eWVudGUuHghDc3NDbGFzcwUTbGFiZWwgbGFiZWwtd2FybmluZx4EXyFTQgICHgdWaXNpYmxlZ2RkAgUPFgIeBXN0eWxlBQ1kaXNwbGF5Ok5vbmU7FggCAQ8WAh8EBQ1kaXNwbGF5Ok5vbmU7ZAIDDxYCHwQFDWRpc3BsYXk6Tm9uZTtkAgUPPCsADwIADxYEHgtfIURhdGFCb3VuZGceC18hSXRlbUNvdW50ZmQKEBYEZgIBAgMCBBYEPCsABQEAFgIeCkhlYWRlclRleHQFC0PDqWR1bGEvUk5DPCsABQEAFgIfBwUUTm9tYnJlL1JhesOzbiBTb2NpYWw8KwAFAQAWAh8HBQpDYXRlZ29yw61hPCsABQEAFgIfBwURUsOpZ2ltZW4gZGUgcGFnb3MWBGZmZmZkAgcPPCsADQEADxYCHwNoZGQYAgUfY3RsMDAkY3BoTWFpbiRndkJ1c2NSYXpvblNvY2lhbA9nZAUjY3RsMDAkY3BoTWFpbiRkdkRhdG9zQ29udHJpYnV5ZW50ZXMPZ2S%2FMyBq0UWtfRBrcaCuie%2FHHkV4Lw%3D%3D&__EVENTVALIDATION=%2FwEWBQLwg%2FG3CgLqq%2F%2FbBAKC%2Fr%2F9AwKhwMi7BAKKnIvVCY5JfDmk%2B3xJ%2BXRVRTKtaXRiF6SZ&__ASYNCPOST=true&ctl00%24cphMain%24btnBuscarPorRNC=Buscar";

            UTF8Encoding encoding = new UTF8Encoding();
            byte[] data = encoding.GetBytes(postData.ToString());

            // Set the content length of the string being posted.
            webrequest.ContentLength = data.Length;

            System.IO.Stream newStream = webrequest.GetRequestStream();
            newStream.Write(data, 0, data.Length);
            newStream.Close();

            HttpWebResponse response = (HttpWebResponse)webrequest.GetResponse();

            using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), encoding))
            {
                string responseText = reader.ReadToEnd();
                Console.WriteLine(responseText);
                return responseText.Contains("No se encontraron datos ");
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant