diff --git a/src/GoogleMeasurementProtocol_NetStandard/Extensions/ListExtensions.cs b/src/GoogleMeasurementProtocol_NetStandard/Extensions/ListExtensions.cs index 3604ff2..3d4abee 100644 --- a/src/GoogleMeasurementProtocol_NetStandard/Extensions/ListExtensions.cs +++ b/src/GoogleMeasurementProtocol_NetStandard/Extensions/ListExtensions.cs @@ -2,13 +2,14 @@ using System.Collections.Generic; using System.Globalization; using System.Net.Http; +using System.Threading.Tasks; using GoogleMeasurementProtocol.Parameters; namespace GoogleMeasurementProtocol.Extensions { public static class ListExtensions { - public static string GenerateQueryString(this List list) + public static async Task GenerateQueryStringAsync(this List list) { if (list == null) { @@ -39,13 +40,13 @@ public static string GenerateQueryString(this List list) using (var formUrlEncodedContent = new FormUrlEncodedContent(paramsDictionary)) { - return formUrlEncodedContent.ReadAsStringAsync().Result; + return await formUrlEncodedContent.ReadAsStringAsync(); } } - public static StringContent GenerateStringContent(this List list) + public static async Task GenerateStringContentAsync(this List list) { - return new StringContent(list.GenerateQueryString()); + return new StringContent(await list.GenerateQueryStringAsync()); } } } diff --git a/src/GoogleMeasurementProtocol_NetStandard/Requests/Batch/BatchRequest.cs b/src/GoogleMeasurementProtocol_NetStandard/Requests/Batch/BatchRequest.cs index 8bbeae0..2f335a1 100644 --- a/src/GoogleMeasurementProtocol_NetStandard/Requests/Batch/BatchRequest.cs +++ b/src/GoogleMeasurementProtocol_NetStandard/Requests/Batch/BatchRequest.cs @@ -38,7 +38,7 @@ private async Task MakeRequestAsync() foreach (var request in _requests) { - sb.AppendLine(request.Parameters.GenerateQueryString()); + sb.AppendLine(await request.Parameters.GenerateQueryStringAsync()); } var response = diff --git a/src/GoogleMeasurementProtocol_NetStandard/Requests/RequestBase.cs b/src/GoogleMeasurementProtocol_NetStandard/Requests/RequestBase.cs index b1b3f9d..67c30f5 100644 --- a/src/GoogleMeasurementProtocol_NetStandard/Requests/RequestBase.cs +++ b/src/GoogleMeasurementProtocol_NetStandard/Requests/RequestBase.cs @@ -34,9 +34,9 @@ internal async Task MakeRequestAsync(string httpMethod, HttpClient httpC ValidateRequestParams(); if (httpMethod == HttpMethod.GET) - return await httpClient.GetStringAsync($"{url}?{Parameters.GenerateQueryString()}").ConfigureAwait(false); + return await httpClient.GetStringAsync($"{url}?{await Parameters.GenerateQueryStringAsync()}").ConfigureAwait(false); - var response = await httpClient.PostAsync(url, Parameters.GenerateStringContent()).ConfigureAwait(false); + var response = await httpClient.PostAsync(url, await Parameters.GenerateStringContentAsync()).ConfigureAwait(false); response.EnsureSuccessStatusCode(); return await response.Content.ReadAsStringAsync();