CODEX

.NET 5 HttpClient PostAsJsonAsync

Alberto De Natale
CodeX
4 min readMar 20, 2021

--

HttpClient.PostAsJsonAsync is one of the new excellent improvements that have been made available with .NET 5.

One of the most accepted way to send a JSON using HttpClient is by serialising an object into a string and wrap it into an StringContent as discussed in this StackOverflow response:

When we must send a huge JSON and/or when this happens often, we might be looking for a means to serialise the object we want to send in small chunks and send them directly to the network.

This couldn’t be easier thanks to PostAsJsonAsync!

HttpClient

HttpClient needs no introductions is one of the best-known .NET classes that allow sending HTTP requests.

Its API is designed to provide an extensible pipeline of handlers. Each handler takes a request and produces a response.

--

--

Alberto De Natale
CodeX

Alberto De Natale is a passionate tech-enthusiast software developer.