function sales_invoice_ubl_upload(url, key, ubl, rid: string): string;
var
idHttp : TIdHTTP;
req : TStringStream;
res : string;
begin
idHttp := TIdHTTP.Create;
try
idHttp.HandleRedirects := False;
idHttp.ReadTimeout := 30000;
idHttp.Request.Accept := 'text/plain';
idHttp.Request.ContentType := 'multipart/form-data';
idHttp.Request.CustomHeaders.Add('ApiKey: '+key);
try
// can i specify such parameters in the url ?
url := url+'/api/publicApi/sales-invoice/ubl/upload?RequestId='+rid+'&sendToCir=No';
// is it correct to define xml and file type ?
ubl := '"ublFile=@'+ubl+';type=text/xml"'; // ?????
res := idHttp.Post(url, ubl);
if idHttp.ResponseCode = 200 then
Result := res
else if idHttp.ResponseCode = 400 then begin
Result := '';
MessageDlg('Request Error !'+#13#13+
IntToStr(IdHttp.ResponseCode)+' '+
idHttp.ResponseText, mtError, [mbOk], 0)
end else begin
Result := '';
MessageDlg('Error: '+IntToStr(IdHttp.ResponseCode)+' '+
idHttp.ResponseText, mtError, [mbOk], 0);
end;
except
on E: Exception do begin
Result := '';
MessageDlg('Check the Internet connection ...'+#13#13+
E.Message, mtError, [mbOk], 0);
end;
end;
finally
idHttp.Free;
Sleep(200);
end;
end;