procedure SendFilesREST(
const PdfFile, XmlFile:
string);
var RESTClient: TRESTClient;
RESTRequest: TRESTRequest;
RESTResponse: TRESTResponse;
begin
RESTRequest:= TRESTRequest.Create(
nil);
try
RESTClient:= TRESTClient.Create(RESTRequest);
RESTResponse:= TRESTResponse.Create(RESTRequest);
RESTRequest.Client:= RESTClient;
RESTRequest.Response:= RESTResponse;
RESTRequest.Method:= rmPost;
RESTRequest.ConnectTimeout:= -1;
RESTRequest.ReadTimeout:= -1;
RESTRequest.Accept := TRESTContentType.ctAPPLICATION_JSON;
RESTRequest.AddAuthParameter('
X-Api-Key', '
My-API-Key', TRESTRequestParameterKind.pkHTTPHEADER);
RESTClient.BaseURL:= '
https://<provider>/Documents/Outbox';
RESTRequest.Method:= rmPOST;
if PdfFile<>'
'
then
RESTRequest.AddFile('
files', PdfFile, TRESTContentType.ctAPPLICATION_PDF);
if XmlFile<>'
'
then
RESTRequest.AddFile('
files', XmlFile, TRESTContentType.ctTEXT_XML);
RESTRequest.Execute;
if RESTResponse.Status.Success
then begin
// ...
end;
finally
RESTRequest.Free;
end;
end;