C# – How to add request headers when using HttpClient

There are two ways add request headers when using HttpClient: In this article, I’ll show examples of both ways to add request headers. Add an unchanging header for all requests Let’s say you’re adding an API Key header. It needs to be included in all requests and the value won’t change. To add this request … Read more

C# – Switch from using HttpWebRequest to HttpClient

There are many reasons to use HttpClient instead of HttpWebRequest. For one, the MSDN docs strongly recommends against using HttpWebRequest, and using HttpClient instead. That should be enough, but if you need a little more convincing, take a look at the Practical reasons to not use HttpWebRequest section below. In addition to explaining why not … Read more

C# – How to make concurrent requests with HttpClient

The HttpClient class was designed to be used concurrently. It’s thread-safe and can handle multiple requests. You can fire off multiple requests from the same thread and await all of the responses, or fire off requests from multiple threads. No matter what the scenario, HttpClient was built to handle concurrent requests. To use HttpClient effectively … Read more