pi_web_api_cs_helper.PIWebAPIClient.PostAsync C# (CSharp) Method

PostAsync() public method

Async POST request. This method makes a HTTP POST request to the uri provided and throws an exception if the response does not indicate a success.
public PostAsync ( string uri, string data ) : System.Threading.Tasks.Task
uri string Endpoint for the POST request.
data string Content for the POST request.
return System.Threading.Tasks.Task
        public async Task PostAsync(string uri, string data)
        {
            HttpResponseMessage response = await _client.PostAsync(uri, new StringContent(data, Encoding.UTF8, "application/json"));
            string content = await response.Content.ReadAsStringAsync();

            if (!response.IsSuccessStatusCode)
            {
                var responseMessage = "Response status code does not indicate success: " + (int)response.StatusCode + " (" + response.StatusCode + " ). ";
                throw new HttpRequestException(responseMessage + Environment.NewLine + content);
            }
        }