METHOD

HttpContent.ReadAsByteArrayAsync

Reads content into a byte array, buffering it. Use only when the size is safely bounded; for untrusted or large bodies enforce a streaming limit instead.

Formal Syntax & Structure

csharp syntaxcsharp
await content.ReadAsByteArrayAsync(cancellationToken)

Working Example

Example Snippetcsharp
using System;using System.IO;using System.Collections.Generic;using System.Net;using System.Net.Http;using System.Net.Http.Headers;using System.Threading;using var content = new ByteArrayContent(new byte[]{1,2});byte[] bytes = await content.ReadAsByteArrayAsync(CancellationToken.None);Console.WriteLine(bytes.Length); // 2
C# & .NET Reference