Content deleted after ContentAsBytes?

Hello,

I just disovered that after reading the content of a response it seems the content empties. After a simple get of an url to get an image I tried to read the data received. Accessing it the first time works fine, but the second read throws an exception. You can reproduce the behaviour with this code:

var
  FBytes : TArray<Byte>;
begin
  FResponse := FClient.Send(FRequest);
  FBytes := Copy(FResponse.ContentAsBytes); // first read
  FBytes := Copy(FResponse.ContentAsBytes); // second read - throws exception

Why is this? Is this a bug or by design?

Regards
Harald

Hello Harald,

It's by design. The content can only be read once, then it's up to you to save it somewhere. In this case, just read from FBytes.
Hello Wagner,
thank You. I thought so. That's why I did it with the copy-function. Is it similar with ContentAsStream? Do I have to copy the content in every way I access it?
Regards
Harald

Yes, in any way you read the content, it should be the only one (it's ready on-the-fly from the other side).