/// <summary> /// Call the given URL asynchronously using an HTTP GET method, expecting returned data. /// </summary> /// <param name="uri"> /// The URI to call. /// </param> /// <returns> /// The result as a string. /// </returns> /// <exception cref="HttpRequestException"> /// The request failed. /// </exception> public virtual async Task <string> GetAsync(string uri) { using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri)) using (HttpResponseMessage response = await HttpClient.SendAsync(request)) { response.EnsureSuccessStatusCode(); string result = await response.Content.ReadAsStringAsync(); if (MerakiHttpApiDebugContext.IsSet()) { Debug.WriteLine($"GET {uri} returned: {result}"); } return(result); } }
/// <summary> /// Call the given URL asynchronously. /// </summary> /// <param name="method"> /// </param> /// <param name="uri"> /// The URI to call. /// </param> /// <param name="content"> /// The optional content to send. /// </param> /// <returns> /// The <see cref="HttpStatusCode"/> representing the result. /// </returns> /// <exception cref="HttpRequestException"> /// The request failed. /// </exception> public virtual async Task <HttpStatusCode> SendAsync(HttpMethod method, string uri, string content = "") { using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri)) { if (MerakiHttpApiDebugContext.IsSet()) { Debug.WriteLine($"{method} {uri} sending: {content}"); } request.Content = new StringContent(content); using (HttpResponseMessage response = await HttpClient.SendAsync(request)) { response.EnsureSuccessStatusCode(); return(response.StatusCode); } } }