Skip to main content

ContentAsASCII

property ContentAsASCII: String read write;

Example

procedure ScriptEvent(var Value: variant);
begin
Http.Get('https://device.example.invalid/v1/health');
if Http.Response.Success then
Value := Trim(Http.Response.ContentAsASCII)
else
Value := 'HTTP ' + IntToStr(Http.Response.ResponseCode);
end;

Usage

ContentAsASCII decodes or rewrites the buffered response body with Velox's seven-bit ASCII encoding.

Additional Technical Info

ContentAsASCII decodes every byte in Content with Delphi's ASCII encoding. It is appropriate only for payloads whose contract is restricted to the ASCII repertoire; it does not inspect response headers or infer a charset.

The getter resets the stream to offset zero, reads its complete size and leaves the position at the end. Because the encoding is explicit, a leading BOM is not removed by Velox's generic detection path.

The setter encodes the value as ASCII, writes at offset zero and rewinds the stream. The shared writer never truncates. A shorter replacement retains old tail bytes, and assigning '' writes zero bytes without clearing anything. Call Content.Clear first when replacing an earlier body.

Non-ASCII characters cannot round-trip through this property and are subject to Delphi's replacement fallback. This limitation is especially important because ContentAsString unexpectedly uses the same ASCII setter despite having a different getter. Use ContentAsUTF8 for general Unicode text.

External references

Created 2026-07-20