From 23b7bbd548f000e7a0eb40a3214f95b8c88f0b75 Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 19 Feb 2024 15:57:28 +0100 Subject: [PATCH] Fixes sending of rewards to bot --- Tools/TestNetRewarder/BotClient.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Tools/TestNetRewarder/BotClient.cs b/Tools/TestNetRewarder/BotClient.cs index e908f895..c112af48 100644 --- a/Tools/TestNetRewarder/BotClient.cs +++ b/Tools/TestNetRewarder/BotClient.cs @@ -2,6 +2,7 @@ using DiscordRewards; using Logging; using Newtonsoft.Json; +using System.Net.Http.Json; namespace TestNetRewarder { @@ -26,7 +27,9 @@ namespace TestNetRewarder public async Task SendRewards(GiveRewardsCommand command) { if (command == null || command.Rewards == null || !command.Rewards.Any()) return false; - return await HttpPost(JsonConvert.SerializeObject(command)) == "OK"; + var result = await HttpPostJson(command); + log.Log("Reward response: " + result); + return result == "OK"; } private async Task HttpGet() @@ -44,12 +47,13 @@ namespace TestNetRewarder } } - private async Task HttpPost(string content) + private async Task HttpPostJson(T body) { try { - var client = new HttpClient(); - var response = await client.PostAsync(GetUrl(), new StringContent(content)); + using var client = new HttpClient(); + using var content = JsonContent.Create(body); + using var response = await client.PostAsync(GetUrl(), content); return await response.Content.ReadAsStringAsync(); } catch (Exception ex)