using System.Net.Http; var request = new HttpRequestMessage(HttpMethod.Post, "http://example.com"); request.Headers.Add("Authorization", "Bearer my_token");
using System.Net.Http; var request = new HttpRequestMessage(HttpMethod.Post, "http://api.example.com"); request.Headers.Add("Accept", "application/json"); request.Headers.Add("Content-Type", "application/json"); string jsonBody = "{ \"name\": \"John\", \"age\": 30 }"; request.Content = new StringContent(jsonBody, Encoding.UTF8, "application/json");Description: In this example, we are creating a new HTTP POST request message with URI "http://api.example.com". We are then adding two headers, Accept and Content-Type, which indicate that we are expecting a JSON response and also sending a JSON payload. Finally, we are setting the request message's content to our JSON payload using the StringContent class. Package library: System.Net.Http and System.Text.Encoding