Comments (4)
Enviado uma possível correção, nos meus teste deu erro 503 e não 400.
from openac.net.nfse.
Show, vou testar e te aviso. Obrigado
from openac.net.nfse.
Usando a rotina genérica (Não retorna nada):
Usando a rotina de envio override (Se chegou a retornar essas infos, deu certo a comunicação):
Se usar esse código no IPM2 a comunicação funciona, como no print acima.
public string ConsultarNFSe(string cabec, string msg) => UploadHttpClient(msg);
protected string UploadHttpClient(string message)
{
var url = Url;
try
{
var auth = Authentication();
var fileName = $"{DateTime.Now:yyyyMMddssfff}_{PrefixoEnvio}_envio.xml";
var arquivoEnvio = Path.Combine(Path.GetTempPath(), fileName);
File.WriteAllText(arquivoEnvio, message);
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, Url);
request.Headers.Add("Authorization", auth);
var content = new StringContent(message);
request.Content = content;
var response = client.SendAsync(request).Result;
response.EnsureSuccessStatusCode();
EnvelopeRetorno = response.Content.ReadAsStringAsync().Result;
return EnvelopeRetorno;
}
finally
{
Url = url;
}
}
Vou te passar no discord o login e senha para testar o caso do IPM2
from openac.net.nfse.
Abaixo o print do teste que não deu certo na rotina genérica:
Aqui com a rotina override que funciona no IPM:
public string ConsultarLoteRps(string cabec, string msg) => UploadIPM(msg);
protected string UploadIPM(string message)
{
var url = Url;
try
{
var auth = Authentication();
var fileName = $"{DateTime.Now:yyyyMMddssfff}_{PrefixoEnvio}_envio.xml";
var arquivoEnvio = Path.Combine(Path.GetTempPath(), fileName);
File.WriteAllText(arquivoEnvio, message);
//Identificate separator
string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
//Encoding
byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
//Creation and specification of the request
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url); //sVal is id for the webService
wr.ContentType = "multipart/form-data; boundary=" + boundary;
wr.Method = "POST";
wr.KeepAlive = true;
wr.Credentials = System.Net.CredentialCache.DefaultCredentials;
wr.Headers.Add("Authorization: " + auth); //AUTHENTIFICATION END
Stream rs = wr.GetRequestStream();
//string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}"; //For the POST's format
//Writting of the file
rs.Write(boundarybytes, 0, boundarybytes.Length);
byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(arquivoEnvio);
rs.Write(formitembytes, 0, formitembytes.Length);
rs.Write(boundarybytes, 0, boundarybytes.Length);
string headerTemplate = $"Content-Disposition: form-data; name=\"file\"; filename=\"{fileName}\"\r\nContent-Type: text/xml\r\n\r\n";
byte[] headerbytes = System.Text.Encoding.UTF8.GetBytes(headerTemplate);
rs.Write(headerbytes, 0, headerbytes.Length);
FileStream fileStream = new FileStream(arquivoEnvio, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[4096];
int bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
rs.Write(buffer, 0, bytesRead);
}
fileStream.Close();
byte[] trailer = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
rs.Write(trailer, 0, trailer.Length);
rs.Close();
rs = null;
WebResponse wresp = null;
try
{
//Get the response
wresp = wr.GetResponse();
Stream stream2 = wresp.GetResponseStream();
StreamReader reader2 = new StreamReader(stream2);
EnvelopeRetorno = reader2.ReadToEnd();
}
catch (Exception ex)
{
string s = ex.Message;
}
finally
{
if (wresp != null)
{
wresp.Close();
wresp = null;
}
wr = null;
}
return EnvelopeRetorno;
}
finally
{
Url = url;
}
}
from openac.net.nfse.
Related Issues (20)
- Documentação HOT 2
- Erro no NFSe HOT 2
- Erro no EnviarLoteRPS do Sigiss HOT 2
- The requested security protocol is not supported HOT 3
- Provedor Americana HOT 3
- Não está funcionando o upload rest no provedor IPM v2 HOT 1
- Crash no provedor IPM HOT 1
- É possível voltar a compilar o projeto em .net 4.5.2 ? HOT 3
- The format of value 'text/xml; charset=utf-8' is invalid.
- Erro ao executar pela segunda vez HOT 1
- Erro ao compilar -> faltou add resource HOT 1
- System.TypeInitializationException: Ao alterar o webservice de uma cidade HOT 3
- Continua sem o arquivo do ginfes HOT 2
- Adição de tabela para listar provedores de NFS-e e suas cidades HOT 1
- Erro envio IISnet HOT 1
- [ERRO]Arquivo de Schema nao Encontrado HOT 4
- NFSe Nacional HOT 1
- ISSSaoPaulo e ISSRio retornando erro de SSL conexão fechada pelo host remoto HOT 4
- Pacote Nuget HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openac.net.nfse.