Unexpected fault. System may be momentarily unavailable or a point error has occurred

Asked

Viewed 449 times

1

I am researching to develop a facilitator of consulting notes tax Nfe Fazenda site, so that the recipient can consult and download.

I created a requisition GET bringing the captcha to use the site’s own security validation and then make a POST with information from CHAVE + Texto which user has entered the captcha at the end returns the answer:

Unexpected fault. System may be momentarily unavailable or a point error has occurred.

Code

public void CarregaCaptcha()
        {


            TempData[CookieTemp] = "";


            CookieContainer cookieJar = new CookieContainer();
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(UrlBase + UrlGet);
            httpWebRequest.CookieContainer = cookieJar;

            var response = httpWebRequest.GetResponse();

            foreach (Cookie c in cookieJar.GetCookies(httpWebRequest.RequestUri))
            {
               TempData["CookieName"] = c.Name;
               TempData["CookieValue"] = c.Value;
            }
 httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            httpWebRequest.Method = WebRequestMethods.Http.Get; //"GET";
            httpWebRequest.AllowAutoRedirect = false;

            StreamReader stHtml = new StreamReader(httpWebRequest.GetResponse().GetResponseStream(), Encoding.GetEncoding("ISO-8859-1"));
            HtmlResponse = stHtml.ReadToEnd();
            stHtml.Close();

UrlImagemCaptcha = GetValue(HtmlResponse, StrImagemCaptcha);

 if (UrlImagemCaptcha.Length > 0)
                ViewBag.Captcha = UrlImagemCaptcha;
            ViewBag.Responde = HtmlResponse;
        }
}

public void ConsultaNfe(string chave, string captcha)
        {
            // Montando a Lista de Parametros para o post
            var parametros = "__EVENTTARGET=&" +
                             "__EVENTARGUMENT=&" +
                             "__VIEWSTATE=" + viewState + "&" +
                             "__VIEWSTATEGENERATOR" + viewGenerator + "&" +
                             "__EVENTVALIDATION=" + Validacao + "&" +
                             "ctl00_txtPalavraChave=&" +                             
                             "ctl00$ContentPlaceHolder1$txtChaveAcessoCompleta=" + chave + "&" +
                             "ctl00$ContentPlaceHolder1$txtCaptcha=" + captcha + "&" +
                             "ctl00$ContentPlaceHolder1$btnConsultar=Continuar" +
                             "ctl00$ContentPlaceHolder1$token=" + token + "&"+
                             "ctl00$ContentPlaceHolder1$captchaSom="+ captchaSom + "&"+
                             "hiddenInputToUpdateATBuffer_CommonToolkitScripts=1";

            MyHttpPost(parametros); 
        }**strong text**
}

public void MyHttpPost(String parametros)
        {

            var request = (HttpWebRequest)WebRequest.Create(UrlBase + UrlPost);
            request.ProtocolVersion = HttpVersion.Version10;
            Uri target = new Uri(UrlBase);
            cookieContainer.Add(new Cookie(TempData["CookieName"].ToString(), TempData["CookieValue"].ToString()) { Domain = target.Host });
            request.CookieContainer = cookieContainer;
            request.Method = "POST";
            request.Timeout = 10000;
            request.AllowAutoRedirect = true;
            request.UserAgent = "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0";


            byte[] byteArray = Encoding.UTF8.GetBytes(parametros);
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;

            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            try
            {
                WebResponse response = request.GetResponse();
                StreamReader stHtml = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("ISO-8859-1"));
                var resposta = stHtml.ReadToEnd();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }enter code here
 }
  • Which address are you firing the requisition?

  • 1

    I am firing at the query address of note http://www.nfe.fazenda.gov.br/portal/consulta.aspx?tipConsulta=completa&tipConteudo=XbSeqxE8pl8=

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.