50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Interfaces;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace CardReaderService
|
|
{
|
|
static class DataCenterHelper
|
|
{
|
|
public static void Post(ILogger logger, CardDataPost postObject, string url)
|
|
{
|
|
var endpointConfig = ConfigurationHandler.ConfigurationHandler.GetConfiguration("DataCenterServiceEndpoint") ??
|
|
"http://localhost:8800";
|
|
|
|
using (var client = new HttpClient())
|
|
{
|
|
var jsonObject = JsonConvert.SerializeObject(postObject);
|
|
var content = new StringContent(jsonObject, Encoding.UTF8, "application/json");
|
|
try
|
|
{
|
|
logger.Trace("Writing");
|
|
var fullUrl = endpointConfig + url;
|
|
var response = client.PostAsync(fullUrl, content).Result;
|
|
logger.Trace("Written");
|
|
}
|
|
catch (Exception)
|
|
{
|
|
Console.WriteLine("exceptioning");
|
|
//ignore
|
|
}
|
|
}
|
|
}
|
|
|
|
public static Task PostAsync(ILogger logger, CardDataPost postObject, string url)
|
|
{
|
|
return Task.Run(() => Post(logger, postObject, url));
|
|
}
|
|
}
|
|
|
|
public class CardDataPost
|
|
{
|
|
public string CardUId { get; set; }
|
|
}
|
|
}
|