HTTP POST for Nota Fiscal

Asked

Viewed 281 times

1

Dear friends, good afternoon. I need to send an XML via post to the webservice function of the São Paulo Fiscal Note. However, XML is correct, it only returns a message that is very generic, so it doesn’t have much to say to you. I would just like you to check if the call I am making is correct, or if there is something wrong. Below is the code.

public string RequestWebService(string wsURL, string param, string action, X509Certificate2 certificado)
        {
            Uri urlpost = new Uri(wsURL);
            HttpWebRequest httpPostConsultaNFe = (HttpWebRequest)HttpWebRequest.Create(urlpost);

            string postConsultaComParametros = param;
            byte[] buffer2 = Encoding.ASCII.GetBytes(postConsultaComParametros);

            httpPostConsultaNFe.CookieContainer = cookies;
            httpPostConsultaNFe.Timeout = 300000;
            httpPostConsultaNFe.ContentType = "text/xml; charset=utf-8; action=" + action;
            httpPostConsultaNFe.Method = "POST";
            httpPostConsultaNFe.ClientCertificates.Add(certificado);
            httpPostConsultaNFe.ContentLength = buffer2.Length;

            Stream PostData = httpPostConsultaNFe.GetRequestStream();
            PostData.Write(buffer2, 0, buffer2.Length);
            PostData.Close();

            HttpWebResponse responsePost = (HttpWebResponse)httpPostConsultaNFe.GetResponse();
            Stream istreamPost = responsePost.GetResponseStream();
            StreamReader strRespostaUrlConsultaNFe = new StreamReader(istreamPost, System.Text.Encoding.ASCII);

            return strRespostaUrlConsultaNFe.ReadToEnd();
        }

Can you help me, please?

Thank you.

No answers

Browser other questions tagged

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