http post using c# code example
Example 1: example HttpClient c# Post
public async string Example()
{
var pocoObject = new
{
Name = "John Doe",
Occupation = "gardener"
};
string json = JsonConvert.SerializeObject(pocoObject);
StringContent data = new StringContent(json, Encoding.UTF8, "application/json");
var url = "https://httpbin.org/post";
var client = new HttpClient();
var response = await client.PostAsync(url, data);
string result = await response.Content.ReadAsStringAsync();
client.Dispose();
return result;
}
Example 2: how make a post request c#
RestClient restClient =
new RestClient(string.Format("{0}/myservice/api/endpoint", "https://exampledomain.com:88"));
RestRequest request = new RestRequest(Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddJsonBody(data);
request.AddHeader("Accept", "application/pdf");
var result = restClient.Execute(request);