Error in Encryption middleware demo

Hello,

sometimes i feel so ignorant... the Encryption middleware demo gives me an error in main.pas (ClientVCL), line 57, this one:

pBytes := TBytes.FromBuffer(ARequest.ContentBuffer^, ARequest.ContentLength);

the error is "[dcc32 Error] Main.pas(57): E2003 Undeclared identifier: 'ContentBuffer"

I've searched a workaround to this, and now i don't know if my code doesn't work for other problems, or if all arise from my bad workaround to that concept of reading the bytes from the Request.

So.. if the demo is erroneous, what is the correct code in that point, to obtain the TBytes content of the Request ?

Thank you, ciao !

Paolo

Indeed a breaking was introduced. Please use this code for the OnSendingRequest event. We will fix the demo for the next release.

    lClient.HttpClient.OnSendingRequest :=
      procedure(ARequest: THttpRequest)
      var
        pBytes: TBytes;
        Stream: TBytesStream;
      begin
        if lToken <> '' then
          ARequest.Headers.SetValue(cHeaderAuthorization, cTokenPrefix + lToken);
        if ARequest.ContentLength > 0 then
        begin
          if lEncrypted then
          begin
            Stream := TBytesStream.Create;
            try
              Stream.CopyFrom(ARequest.ContentStream);
              pBytes := Copy(Stream.Bytes, 0, Stream.Size);
              pBytes := TAESFunc.Encrypt(pBytes, TAESKeys.GetReceiveKey);
              ARequest.SetContent(pBytes);
            finally
              Stream.Free;
            end;
          end
          else
            ARequest.Headers.AddValue(cCustomXDataHeader, TAESKeys.GetHeaderKey)
        end;
      end;

Thank you Wagner, ciao !

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.