Answers for "stringcontent object"

0

stringcontent object

private async Task PostToAPI(object myObject, string endpointUri, string endpointDirectory)
{
    string myObjectAsJSON = System.Web.Helpers.Json.Encode(myObject);
    StringContent stringContent = new StringContent(myObjectAsJSON, Encoding.UTF8, "application/json");
    using (HttpClient httpClient = new HttpClient())
    {
        httpClient.BaseAddress = new Uri(endpointUri);
        using (HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(endpointDirectory, stringContent).ConfigureAwait(false))
        {
            // Do something
        }
    }
}
Posted by: Guest on August-18-2020

Browse Popular Code Answers by Language