Calling RESTful endpoints

HttpClient

using (var client = new HttpClient())
{
using (var content = new StringContent(json, Encoding.UTF8, "application/json"))
{
var result = client.PostAsync(endPoint, content).Result;
}
}

WebRequest

var endPoint = string.Format("{0}/fizzbuzz_event", ApiUrl);
WebRequest request = WebRequest.Create(endPoint);
request.Method = "POST";
request.ContentType = "application/json";

var dataStream = request.GetRequestStream();
dataStream.Write(new UTF8Encoding().GetBytes(json), 0, json.Length);

Leave a Reply