/// <summary>Automatically builds a POST query string from a <see cref="StringPairCollection"/> /// using <see cref="Encoding.UTF8"/> encoding and the provided Content-Type.</summary> /// <returns>The <see cref="HttpResponseMessage"/> content converted to a <see cref="string"/>.</returns> public static async Task <string> PostToStringAsync (this HttpClient httpClient, string url, StringPairCollection pairs, CancellationToken cancellationToken = default, string mediaType = "application/x-www-form-urlencoded") { var response = await httpClient.PostAsync(url, pairs, cancellationToken, mediaType); return(await response.Content.ReadAsStringAsync().ConfigureAwait(false)); }
/// <summary>Automatically builds a GET query string from a <see cref="StringPairCollection"/> /// and appends it to the provided URL.</summary> /// <returns>The <see cref="HttpResponseMessage"/> content converted to a string.</returns> public async static Task <string> GetStringAsync (this HttpClient httpClient, string url, StringPairCollection pairs, CancellationToken cancellationToken = default) { var response = await httpClient.GetAsync(url, pairs, cancellationToken); return(await response.Content.ReadAsStringAsync().ConfigureAwait(false)); }
/* * POST METHODS */ /// <summary>Automatically builds a POST query string from a <see cref="StringPairCollection"/> /// using <see cref="Encoding.UTF8"/> encoding and the provided Content-Type.</summary> public static async Task <HttpResponseMessage> PostAsync (this HttpClient httpClient, string url, StringPairCollection pairs, CancellationToken cancellationToken = default, string mediaType = "application/x-www-form-urlencoded") { return(await httpClient.PostAsync(url, new StringContent(pairs.ToHttpQueryString(), Encoding.UTF8, mediaType), cancellationToken).ConfigureAwait(false)); }
/* * GET METHODS */ /// <summary>Automatically builds a GET query string from a <see cref="StringPairCollection"/> /// and appends it to the provided URL.</summary> public async static Task <HttpResponseMessage> GetAsync (this HttpClient httpClient, string url, StringPairCollection pairs, CancellationToken cancellationToken = default) { return(await httpClient.GetAsync($"{url}?{pairs.ToHttpQueryString()}", cancellationToken)); }