From 163bbc72c34fac9d4033239f9f56b1866aa6e3de Mon Sep 17 00:00:00 2001 From: Nastro_ Date: Thu, 20 Mar 2025 17:19:47 +0100 Subject: [PATCH] fixed insert tokens --- LoadTest/Program.cs | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/LoadTest/Program.cs b/LoadTest/Program.cs index c4bfb4c..c517f7c 100644 --- a/LoadTest/Program.cs +++ b/LoadTest/Program.cs @@ -6,7 +6,6 @@ //Numero Thread(?) using System.Diagnostics; -using System.Net.Sockets; namespace LoadTest; @@ -24,6 +23,7 @@ internal class Program string? yn; Stopwatch sw; + using var client = new HttpClient(); Console.WriteLine("Load Test"); do { @@ -46,25 +46,36 @@ internal class Program body = Console.ReadLine(); } while (string.IsNullOrEmpty(body)); } - + do { - Console.WriteLine("Is Authentication required? (Y/N)"); + Console.WriteLine("Are Tokens required? (Y/N)"); yn = Console.ReadLine(); } while(string.IsNullOrEmpty(yn) && (yn?.ToLower() != ConsoleKey.Y.ToString().ToLower() || yn?.ToLower() != ConsoleKey.N.ToString().ToLower())); if (yn?.ToLower() == "y") { + ConsoleKey keyPressed; do { - Console.WriteLine("Header"); - header = Console.ReadLine(); - } while (string.IsNullOrEmpty(header)); - do + do + { + Console.WriteLine("Header"); + header = Console.ReadLine(); + } while (string.IsNullOrEmpty(header)); + + do + { + Console.WriteLine("Token: "); + token = Console.ReadLine(); + } while (string.IsNullOrEmpty(token)); + Console.WriteLine("Press a key to insert another token, Press Q to stop inserting tokens."); + keyPressed = Console.ReadKey().Key; + } while (keyPressed == ConsoleKey.Q); + if (!string.IsNullOrEmpty(token) && !string.IsNullOrEmpty(header)) { - Console.WriteLine("Token: "); - token = Console.ReadLine(); - } while (string.IsNullOrEmpty(token)); + client.DefaultRequestHeaders.Add(header, token); + } } do @@ -74,12 +85,7 @@ internal class Program } while (string.IsNullOrEmpty(time)); lTime = long.Parse(time) * 1000; - - using var client = new HttpClient() ; - if (yn == "y" && !string.IsNullOrEmpty(token) && !string.IsNullOrEmpty(header)) - { - client.DefaultRequestHeaders.Add(header, token); - } + switch (methodHttp.ToUpper()) { case "GET":