0
I’m trying to consult the webservice
of Sephaz.
"https://www1.cte.fazenda.gov.br/CTeDistribuicaoDFe/CTeDistribuicaoDFe.asmx"
I’m getting the error below:
"403 Forbidden - Access Denied".
The message seems clear, but I’m passing a valid digital certificate.
Follow the code snippet below the call:
var url = "https://www1.cte.fazenda.gov.br/CTeDistribuicaoDFe/CTeDistribuicaoDFe.asmx";
var web = (HttpWebRequest)WebRequest.Create(url);
web.Method = "POST";
web.ContentType = "text/xml;charset=utf-8";
web.Accept = "text/xml";
web.Headers.Clear();
web.Headers.Add("SOAPAction", url);
X509Certificate2 certificado = ObterCertificado();
if (certificado != null)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
web.ClientCertificates.Add(certificado);
}
var soap = "<?xml version='1.0' encoding='UTF-8'?>";
soap += "<soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'>";
soap += "<soap12:Body>";
soap += " <cteDistDFeInteresse xmlns='http://www.portalfiscal.inf.br/cte/wsdl/CTeDistribuicaoDFe'>";
soap += " <distDFeInt xmlns='http://www.portalfiscal.inf.br/cte' versao='1.00'>";
soap += " <tpAmb>1</tpAmb>";
soap += " <cUFAutor>91</cUFAutor>";
soap += " <CNPJ>00000000000000</CNPJ>";
soap += " <distNSU><ultNSU>000000000000000</ultNSU></distNSU>";
soap += " </distDFeInt>";
soap += " </cteDistDFeInteresse>";
soap += "</soap12:Body>";
soap += "</soap12:Envelope>";
// soap = "<cteDadosMsg><distDFeInt xmlns='http://www.portalfiscal.inf.br/nfe' versao='1.00'><tpAmb>1</tpAmb><cUFAutor>35</cUFAutor><CNPJ>000000000000000</CNPJ><distNSU><ultNSU>000000000000002</ultNSU></distNSU></distDFeInt></cteDadosMsg>";
var byteArray = Encoding.UTF8.GetBytes(soap);
web.ContentLength = byteArray.Length;
using (var stream = web.GetRequestStream())
{
stream.Write(byteArray, 0, byteArray.Length);
}
using (var webResponse = (HttpWebResponse)web.GetResponse())
{
using (var stream = webResponse.GetResponseStream())
{
retorno = new StreamReader(stream).ReadToEnd();
}
}
Fabio that
layout
ofxml
that is correct?– JcSaint
@Jcsaint, in fact, the problem was in the digital certificate itself. It was not valid, I think I passed in that.
– Fabio Henrique
right, it’s just that my
xml
consultation is a little different...– JcSaint