Skip to content

Instantly share code, notes, and snippets.

@acras
Last active November 25, 2016 17:33
Show Gist options
  • Save acras/52817d0c7fd34c02ff7cc2e2105af5f3 to your computer and use it in GitHub Desktop.
Save acras/52817d0c7fd34c02ff7cc2e2105af5f3 to your computer and use it in GitHub Desktop.
procedure autorizarNFe(jsonNFe: TStringList);
var
http: TIdHTTP;
url, resp, prodOrHom: string;
strs: TStringStream;
strl: TStringList;
zippedParams: TMemoryStream;
zipper: TAbZipper;
begin
if producao then
prodOrHom := 'https://api.focusnfe.com.br'
else
prodOrHom := 'https://homologacao.acrasnfe.acras.com.br';
http := TIdHTTP.Create(nil);
try
strs := TStringStream.Create(utf8Encode(jsonNFe.asString), TEncoding.UTF8);
url := prodOrHom + '/nfce.json?token='+config.token+'&ref=' + ref;
http.Request.CharSet := 'utf-8';
http.Request.ContentEncoding := 'gzip';
zippedParams := TMemoryStream.Create;
zipper := TAbZipper.Create(nil);
try
zipper.ArchiveType := atGzip;
zipper.ForceType := true;
zipper.Stream := zippedParams;
zipper.AddFromStream('', strs);
try
resp := http.Post(url, zippedParams);
//gerenciar a resposta
except
on E: EIdHTTPProtocolException do
begin
//tratar erros
end
else
raise;
end;
finally
freeAndNil(zipper);
freeAndNil(zippedParams);
end;
finally
http.Free;
strs.Free;
end;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment