Skip to content

Commit

Permalink
using static HttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
cadon committed Jan 1, 2024
1 parent 0832b54 commit 8892ee1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions ARKBreedingStats/AsbServer/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}");
}
}

Expand Down

0 comments on commit 8892ee1

Please sign in to comment.