diff --git a/Projects/DLL/SystemX.Core.dll b/Projects/DLL/SystemX.Core.dll index edd1a49..13fafeb 100644 Binary files a/Projects/DLL/SystemX.Core.dll and b/Projects/DLL/SystemX.Core.dll differ diff --git a/Projects/SystemX.Core/SystemX.Core/Communication/Http.cs b/Projects/SystemX.Core/SystemX.Core/Communication/Http.cs index 6198ff4..0a040d0 100644 --- a/Projects/SystemX.Core/SystemX.Core/Communication/Http.cs +++ b/Projects/SystemX.Core/SystemX.Core/Communication/Http.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json.Linq; +using Azure.Core; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; @@ -95,6 +96,55 @@ namespace SystemX.Core.Communication return response; } + + /// + /// PutJsonAsnyc + /// + /// https://127.0.0.1:443 + /// Range 5~30 secconds + public virtual async Task PutJsonAsync(string url, REQUEST request, string bearerToken = "", short timeOutSeconds = 10) where REQUEST : class where RESPONSE : class + { + RESPONSE? response = default(RESPONSE); + Guid guid = Guid.NewGuid(); + + using (HttpClient httpClient = new HttpClient(GetClientHandler())) + { + var timeOutSec = SetTimeout(timeOutSeconds); + httpClient.Timeout = new TimeSpan(0, 0, timeOutSec); + httpClient.BaseAddress = new Uri($"{url}"); + + if (string.IsNullOrEmpty(bearerToken) == false) + httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", $"{bearerToken}"); + + int retry = 0; + while (true) + { + await Task.Delay(1); + try + { + LogXnet.WriteLine($"[PUT] Request({guid})::{url}{Environment.NewLine}{request?.ToJson()}", LogXLabel.HTTP); + + DateTime requestTime = DateTime.Now; + var res = await httpClient.PutAsJsonAsync(url, request); + response = await res.Content.ReadFromJsonAsync(); + + LogXnet.WriteLine($"[PUT] Rseponse({guid}) ({(DateTime.Now - requestTime).TotalSeconds} sec)::{url}{Environment.NewLine}{response?.ToJson()}", LogXLabel.HTTP); + break; + } + catch (Exception e) + { + LogXnet.WriteLine(e); + retry += 1; + } + + if (retry > 1) + break; + } + } + + return response; + } + public virtual async Task GetStreamAsync(string url, string bearerToken = "", short timeOutSeconds = 10) { Guid guid = Guid.NewGuid();