From 3ba63ccb686fe07942d1c3e70e253d6d73789b53 Mon Sep 17 00:00:00 2001 From: SHM Date: Mon, 3 Nov 2025 08:58:51 +0900 Subject: [PATCH] =?UTF-8?q?[=EC=84=B1=ED=98=84=EB=AA=A8]=20RestAPI=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Projects/NetStandard/CPMeta/RestAPI.cs | 31 +++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Projects/NetStandard/CPMeta/RestAPI.cs b/Projects/NetStandard/CPMeta/RestAPI.cs index d7bc82f..7375c7f 100644 --- a/Projects/NetStandard/CPMeta/RestAPI.cs +++ b/Projects/NetStandard/CPMeta/RestAPI.cs @@ -10,22 +10,27 @@ namespace CPMeta { public class RestAPI { + private static HttpClient RequestClient = new HttpClient(); + private static HttpClient ResponseClient = new HttpClient(); + + static RestAPI() + { + ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + RequestClient.Timeout = TimeSpan.FromMilliseconds(3000); + ResponseClient.Timeout = TimeSpan.FromMilliseconds(3000); + } + public static async Task PostAsync(string Url, REQUEST body) where REQUEST : class where RESPONSE : class { try { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; - if (body != null) { var jsonBody = JsonConvert.SerializeObject(body); - var contents = new StringContent(jsonBody, Encoding.UTF8, "application/json"); + var contents = new StringContent(jsonBody, Encoding.UTF8, "application/json"); - HttpClient client = new HttpClient(); - client.Timeout = TimeSpan.FromMilliseconds(3000); - - var response = await client.PostAsync(Url, contents); + var response = await RequestClient.PostAsync(Url, contents); var resContentStr = await response.Content.ReadAsStringAsync(); return JsonConvert.DeserializeObject(resContentStr); @@ -34,6 +39,7 @@ namespace CPMeta catch (Exception e) { Console.WriteLine("PostAsync Error"); + Console.WriteLine(e.Message); } return default(RESPONSE); @@ -43,13 +49,7 @@ namespace CPMeta { try { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; - - HttpClient client = new HttpClient(); - client.Timeout = TimeSpan.FromMilliseconds(3000); - - var response = await client.GetAsync(Url); + var response = await ResponseClient.GetAsync(Url); var resContentStr = await response.Content.ReadAsStringAsync(); return JsonConvert.DeserializeObject(resContentStr); @@ -58,6 +58,7 @@ namespace CPMeta catch(Exception e) { Console.WriteLine("GetAsync Error"); + Console.WriteLine(e.Message); } return default(RESPONSE);