[성현모] SystemX.Core Http Put 메소드 추가

This commit is contained in:
SHM
2025-12-17 10:59:15 +09:00
parent e94cd80675
commit 1487165816
2 changed files with 51 additions and 1 deletions

Binary file not shown.

View File

@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq; using Azure.Core;
using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -95,6 +96,55 @@ namespace SystemX.Core.Communication
return response; return response;
} }
/// <summary>
/// PutJsonAsnyc
/// </summary>
/// <param name="url">https://127.0.0.1:443</param>
/// <param name="timeOutSeconds">Range 5~30 secconds</param>
public virtual async Task<RESPONSE?> PutJsonAsync<REQUEST, RESPONSE>(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<RESPONSE>();
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<Stream?> GetStreamAsync(string url, string bearerToken = "", short timeOutSeconds = 10) public virtual async Task<Stream?> GetStreamAsync(string url, string bearerToken = "", short timeOutSeconds = 10)
{ {
Guid guid = Guid.NewGuid(); Guid guid = Guid.NewGuid();