54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using NLog;
|
|
using NLog.LayoutRenderers;
|
|
using System.Configuration;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GenDocCli
|
|
{
|
|
public class ApiClient
|
|
{
|
|
private static readonly Logger Logger =
|
|
LogManager.GetCurrentClassLogger();
|
|
|
|
private readonly string _url;
|
|
private readonly string _token;
|
|
|
|
public ApiClient()
|
|
{
|
|
_url = GenDocCLI.Properties.Settings.Default.API;
|
|
_token = GenDocCLI.Properties.Settings.Default.Token;
|
|
}
|
|
|
|
public async Task<bool> CallGenDoc(string json)
|
|
{
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization =
|
|
new AuthenticationHeaderValue(
|
|
"Bearer",
|
|
_token);
|
|
|
|
var content = new StringContent(
|
|
json,
|
|
Encoding.UTF8,
|
|
"application/json");
|
|
|
|
HttpResponseMessage response =
|
|
await client.PostAsync(_url, content);
|
|
|
|
string responseText =
|
|
await response.Content.ReadAsStringAsync();
|
|
|
|
Logger.Debug(
|
|
"HTTP {0} Response: {1}",
|
|
(int)response.StatusCode,
|
|
responseText);
|
|
|
|
return response.IsSuccessStatusCode;
|
|
}
|
|
}
|
|
}
|
|
} |