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# – 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