barcode-host/Server/Services/PostService.cs
2023-06-23 15:40:59 -07:00

34 lines
1.2 KiB
C#

using Barcode.Host.Shared.Models;
using Barcode.Host.Shared.Models.Stateless;
using System.Text;
namespace Barcode.Host.Server.Services;
public class PostService : IPostService
{
private static Task<HttpResponseMessage> PostAsync(string postTo, HttpClient httpClient, Notification notification)
{
Task<HttpResponseMessage> result;
string json = System.Text.Json.JsonSerializer.Serialize(notification);
StringContent stringContent = new(json, Encoding.UTF8, "application/json");
result = httpClient.PostAsync(postTo, stringContent);
return result;
}
Task<HttpResponseMessage> IPostService.PostAsync(string postTo, HttpClient httpClient, Notification notification)
{
Task<HttpResponseMessage> result = PostAsync(postTo, httpClient, notification);
return result;
}
HttpResponseMessage IPostService.Post(string postTo, HttpClient httpClient, Notification notification)
{
HttpResponseMessage result;
Task<HttpResponseMessage> httpResponseMessage = PostAsync(postTo, httpClient, notification);
httpResponseMessage.Wait();
result = httpResponseMessage.Result;
return result;
}
}