You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using Estsh.Core.Quartz.BaseJobs;
|
|
using Microsoft.AspNetCore.Antiforgery;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Estsh.Core.Quartz.Extensions
|
|
{
|
|
public static class HttpClientFactoryExtension
|
|
{
|
|
private static ILogger<ClassLibraryJob> _logger { get; set; }
|
|
public static async Task<string> HttpSendAsync(this IHttpClientFactory httpClientFactory, HttpMethod method, string url, Dictionary<string, string> headers = null)
|
|
{
|
|
var client = httpClientFactory.CreateClient();
|
|
var content = new StringContent("");
|
|
// content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
|
|
var request = new HttpRequestMessage(method, url)
|
|
{
|
|
Content = content
|
|
};
|
|
if (headers != null)
|
|
{
|
|
foreach (var header in headers)
|
|
{
|
|
request.Headers.Add(header.Key, header.Value);
|
|
}
|
|
}
|
|
try
|
|
{
|
|
HttpResponseMessage httpResponseMessage = await client.SendAsync(request);
|
|
|
|
var result = await httpResponseMessage.Content
|
|
.ReadAsStringAsync();
|
|
return result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.WriteLine(ex.Message);
|
|
return ex.Message;
|
|
}
|
|
}
|
|
}
|
|
}
|