C# – Disposing the request HttpContent when using HttpClient

In versions before .NET Core 3.0 (including .NET Framework), HttpClient disposes the request HttpContent object for you. This is surprising default behavior (a violation of the principle of least surprise for sure). This causes multiple problems, but one of the main problems is it prevents you from reusing the HttpContent object (you’re greeted with an … Read more

C# – How to send a file with HttpClient

In order to send a file in a request with HttpClient, add the file into a MultipartFormDataContent object, and send this object as the request content. Here’s an example: This sends the following multipart/form-data POST request: In this article, I’ll explain a few details about MultipartFormDataContent, and show a few other file-sending scenarios. MultipartFormDataContent Add() … Read more

C# – Get a file’s checksum using any hashing algorithm

This article shows how to get a file’s checksum using any of these hashing algorithms: MD5, SHA1, SHA256, SHA384, and SHA512. If you are only interested getting a specific type of checksum, take a look at the first section. If you’re interested in a general-purpose checksum method that allows you to generate the checksum using … Read more