[성현모] SystemX.Core Http Put 메소드 추가
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
||||
/// <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)
|
||||
{
|
||||
Guid guid = Guid.NewGuid();
|
||||
|
||||
Reference in New Issue
Block a user