From 8892ee10ffc77fa462c9db690e7e200c56539d7c Mon Sep 17 00:00:00 2001 From: cadon Date: Tue, 2 Jan 2024 00:13:48 +0100 Subject: [PATCH] using static HttpClient --- ARKBreedingStats/AsbServer/Connection.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ARKBreedingStats/AsbServer/Connection.cs b/ARKBreedingStats/AsbServer/Connection.cs index cee24de1..40a49a0c 100644 --- a/ARKBreedingStats/AsbServer/Connection.cs +++ b/ARKBreedingStats/AsbServer/Connection.cs @@ -37,7 +37,7 @@ public static async void StartListeningAsync( try { - using (var client = new HttpClient()) + var client = FileService.GetHttpClient; using (var response = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead)) { if (!response.IsSuccessStatusCode) @@ -186,16 +186,17 @@ public static async void SendCreatureData(Creature creature, string token) { if (creature == null || string.IsNullOrEmpty(token)) return; - using (var client = new HttpClient()) + var client = FileService.GetHttpClient; + + var contentString = Newtonsoft.Json.JsonConvert.SerializeObject(ImportExportGun.ConvertCreatureToExportGunFile(creature, out _)); + var msg = new HttpRequestMessage(HttpMethod.Put, ApiUri + "export/" + token); + msg.Content = new StringContent(contentString, Encoding.UTF8, "application/json"); + msg.Content.Headers.Add("Content-Length", contentString.Length.ToString()); + using (var response = await client.SendAsync(msg)) { - var contentString = Newtonsoft.Json.JsonConvert.SerializeObject(ImportExportGun.ConvertCreatureToExportGunFile(creature, out _)); - var msg = new HttpRequestMessage(HttpMethod.Put, ApiUri + "export/" + token); - msg.Content = new StringContent(contentString, Encoding.UTF8, "application/json"); - msg.Content.Headers.Add("Content-Length", contentString.Length.ToString()); - var response = await client.SendAsync(msg); Console.WriteLine($"Sent creature data of {creature} using token: {token}\nContent:\n{contentString}"); Console.WriteLine(msg.ToString()); - Console.WriteLine($"Response: Status: {(int)response.StatusCode}, ReasonPhrase: {response.ReasonPhrase}"); + Console.WriteLine($"Response: StatusCode {(int)response.StatusCode}, ReasonPhrase: {response.ReasonPhrase}"); } }