Use HttpClient
class for issueing post web requests and other types of requests.
It is a newer API for working with HTTP and is designed to work well with web APIs,
REST-based services, and custom authentication schemes. In .NET Framework, HttpClient
relied on WebRequest and WebResponse, but starting with .NET Core 3, it handles HTTP itself.
Below is the code for making a post request.
using System.Net.Http;
private static readonly HttpClient client = new();
var values = new Dictionary<string, string>
{
{ "thing1", "hello" },
{ "thing2", "world" }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync(
"http://www.example.com/postable.aspx", content);
var result = await response.Content.ReadAsStringAsync();