Get raw Json for TXDataClient-Call

Hi,

i'm trying to retrieve the raw content of the HTTP response when a service method is called via TXDataClient. This is for debugging purposes.

To do this, I'm connecting the "OnResponseReceived" event of TXDataClient.HTTPClient to an event handler.

When I try to access the content using "var ContentText := TEncoding.UTF8.GetString(AResponse.ContentAsBytes);", i get an error message.

The error message is: "EInvalidStateException with the message 'Expected BeginObject but was EOF at path $'".

The content is being retrieved, but I think this is probably the wrong approach. What is the correct approach?

Thank you very much in advance.

A response content stream (or bytes) is unidirectional. If you read the content, you have to provide a new response object with the same content. Here is an example:

Client.OnResponseReceived := procedure(Req: THttpRequest; var Resp: THttpResponse)
begin
  Resp := THttpCachedResponse.Create(Resp);
  var TextResponse := TEncoding.UTF8.GetString(Resp.ContentAsBytes);
end;

Thank you for the quick reply. It works perfectly.

By the way: Thank you for a great product and all the hard work you and your team have put into it.

Thank you very much for the kind words, @Ernst_Henry!

It's rewarding to know that our work is appreciated and is being useful for our customers.