# NFSe - Brasilia PHP

**URL:** <https://comunidade.opendfe.com.br/t/nfse-brasilia-php/705>\
**Category:** Distrito Federal\
**Tags:** php\
**Created:** [Outubro 10, 2022, 7:39pm UTC](https://comunidade.opendfe.com.br/t/nfse-brasilia-php/705 "2022-10-10T19:39:37Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![luizvaz](https://comunidade.opendfe.com.br/user_avatar/comunidade.opendfe.com.br/luizvaz/32/4_2.png) [@luizvaz](https://comunidade.opendfe.com.br/u/luizvaz)\
**Post date:** [Outubro 11, 2022, 3:59pm UTC](https://comunidade.opendfe.com.br/t/nfse-brasilia-php/705/5 "2022-10-11T15:59:26Z")

</div>

Ah bom!

Eu tenho esse código em `C#`:

```auto

        public string SendRequest(string data, string action)
        {
            try
            {
                WebRequestHandler handler = new WebRequestHandler();
                if (this.Certificado != null)
                    handler.ClientCertificates.Add(this.Certificado);
                HttpClient client = new HttpClient(handler);
                client.DefaultRequestHeaders.ExpectContinue = false;
                client.DefaultRequestHeaders.Add("Accept", "*/*");
                //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/soap+xml"));
                //client.DefaultRequestHeaders.Add("SOAPAction", action);
                client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.8806)");
                client.DefaultRequestHeaders.TransferEncodingChunked = null;

                StringContent queryString = new StringContent(data, Encoding.UTF8, "text/xml");
                HttpResponseMessage response = client.PostAsync(new Uri(this.Url), queryString).Result;
                String responseValue = string.Empty;
                Stream responseStream = null;

                /*
                if (response != null)
                {
                    //response.EnsureSuccessStatusCode();
                    this.cLastCode = response.StatusCode;

                    Task task = response.Content.ReadAsStringAsync().ContinueWith(t =>
                    {
                        responseValue = t.Result;
                    });

                    task.Wait();
                };
                */

                if (response != null)
                {
                    Task task = response.Content.ReadAsStreamAsync().ContinueWith(t =>
                    {
                        responseStream = t.Result;
                    });
                    task.Wait();

                    string encoding = String.Join(",", response.Content.Headers.ContentEncoding);

                    if (response.Content.Headers.ContentEncoding.Contains("gzip"))
                        responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
                    else if (response.Content.Headers.ContentEncoding.Contains("deflate"))
                        responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);

                    using (StreamReader streamReader = new StreamReader(responseStream))
                    {
                        responseValue = streamReader.ReadToEnd();
                    }

                }

                return responseValue;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public string ConsultarLoteRps(string CNPJ, string IM, string Protocolo)
        {
            String NfseDados = String.Format(
                "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;" +
                "&lt;ConsultarLoteRpsEnvio xmlns=\"http://www.issnetonline.com.br/webserviceabrasf/vsd/servico_consultar_lote_rps_envio.xsd\" " +
                                         " xmlns:tc=\"http://www.issnetonline.com.br/webserviceabrasf/vsd/tipos_complexos.xsd\"&gt;" +
                "&lt;Prestador&gt;" +
                "&lt;tc:CpfCnpj&gt;" +
                "&lt;tc:Cnpj&gt;{0}&lt;/tc:Cnpj&gt;" +
                "&lt;/tc:CpfCnpj&gt;" +
                "&lt;tc:InscricaoMunicipal&gt;{1}&lt;/tc:InscricaoMunicipal&gt;" +
                "&lt;/Prestador&gt;" +
                "&lt;Protocolo&gt;{2}&lt;/Protocolo&gt;" +
                "&lt;/ConsultarLoteRpsEnvio&gt;", CNPJ, IM, Protocolo);

            String s = String.Format(
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
                "<S:Body>" +
                "<ConsultarLoteRps xmlns=\"http://www.issnetonline.com.br/webservice/nfd\">" +
                "<xml>{0}</xml>" +
                "</ConsultarLoteRps>" +
                "</S:Body></S:Envelope>",
                NfseDados);

            File.WriteAllText(cFileName.Replace(".xml", ".soap.xml"), s);

            return this.SendRequest(s, "http://www.issnetonline.com.br/webservice/nfd/ConsultarLoteRps");
        }

        public String ConsultarNfsePorRps(String CNPJ, String IM, String RPS, String SERIE)
        {
            String NfseDados = String.Format(
                "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;" +
                "&lt;ConsultarNfseRpsEnvio xmlns=\"http://www.issnetonline.com.br/webserviceabrasf/vsd/servico_consultar_nfse_rps_envio.xsd\" " +
                                         " xmlns:tc=\"http://www.issnetonline.com.br/webserviceabrasf/vsd/tipos_complexos.xsd\"&gt;" +
                "&lt;IdentificacaoRps&gt;" +
                "&lt;tc:Numero&gt;{0}&lt;/tc:Numero&gt;" +
                "&lt;tc:Serie&gt;{1}&lt;/tc:Serie&gt;" +
                "&lt;tc:Tipo&gt;1&lt;/tc:Tipo&gt;" +
                "&lt;/IdentificacaoRps&gt;" +
                "&lt;Prestador&gt;" +
                "&lt;tc:CpfCnpj&gt;&lt;tc:Cnpj&gt;{2}&lt;/tc:Cnpj&gt;&lt;/tc:CpfCnpj&gt;" +
                "&lt;tc:InscricaoMunicipal&gt;{3}&lt;/tc:InscricaoMunicipal&gt;" +
                "&lt;/Prestador&gt;" +
                "&lt;/ConsultarNfseRpsEnvio&gt;", RPS, SERIE, CNPJ, IM);

            String s = String.Format(
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
                "<soap:Body>" +
                "<ConsultarNFSePorRPS xmlns =\"http://www.issnetonline.com.br/webservice/nfd\">" +
                "<xml>{0}</xml>" +
                "</ConsultarNFSePorRPS>" +
                "</soap:Body>" +
                "</soap:Envelope>",
                NfseDados);

            File.WriteAllText(cFileName.Replace(".xml", ".soap.xml"), s);

            return this.SendRequest(s, "http://www.issnetonline.com.br/webservice/nfd/ConsultarNFSePorRPS");
        }

```

---

_[View the full topic](https://comunidade.opendfe.com.br/t/nfse-brasilia-php/705)._
