PostService
This commit is contained in:
34
Server/Services/PostService.cs
Normal file
34
Server/Services/PostService.cs
Normal file
@ -0,0 +1,34 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user