CodeLiturgy.Dashboard/BlueWest.BinanceDataAgent/Core/Http/AgentHttp.cs

33 lines
941 B
C#

using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using BlueWest.Core.Tests;
namespace BlueWest.DataAgent
{
public static class AgentHttp
{
private static readonly HttpClient Client = new HttpClient();
public static async Task<string> PostAsync<T>(string uri, object data)
{
var values = data.ToDictionary();
ByteArrayContent content = new FormUrlEncodedContent((IEnumerable<KeyValuePair<string?, string?>>) values);
var response = await Client.PostAsync(uri, content);
var responseString = await response.Content.ReadAsStringAsync();
return responseString;
}
public static async Task<string> GetAsync(string uri)
{
var responseString = await Client.GetStringAsync(uri);
return responseString;
}
}
}