Util - use static HttpClient httpClientEngine as field.

This commit is contained in:
DucDangAnh 2020-06-29 15:19:36 +07:00
parent 148896423f
commit cc92f80a45

View File

@ -10,6 +10,8 @@ namespace AIParkingApplication
{
public static class Util
{
private static HttpClient httpClientEngine = new HttpClient { BaseAddress = new Uri("http://localhost:8080/"), Timeout = TimeSpan.FromMilliseconds(5000) };
public static bool IsPingable(string destinationIPAddress, out long pingTime, int timeOut = UtilConstant.PING_TIMEOUT_MS)
{
var pingTask = Task.Factory.StartNew(async () =>
@ -54,8 +56,6 @@ namespace AIParkingApplication
{
string plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes());
try
{
using (var client = new HttpClient { BaseAddress = new Uri("http://localhost:8080/"), Timeout = TimeSpan.FromMilliseconds(5000) })
{
var request = new PlateRequestEngineModel
{
@ -63,12 +63,11 @@ namespace AIParkingApplication
Mode = plateType == PlateType.Square ? "square" : "long",
Display = "full"
};
HttpResponseMessage response = await client.PostAsJsonAsync("/get-from-frame", request);
HttpResponseMessage response = await httpClientEngine.PostAsJsonAsync("/get-from-frame", request);
response.EnsureSuccessStatusCode();
var ocrResult = await response.Content.ReadAsAsync<OcrResult>();
return ocrResult;
}
}
catch (Exception ex)
{
Console.WriteLine($"SendEngineRequest : {ex.Message}");