21 lines
764 B
C#
21 lines
764 B
C#
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using LinkToolAddin.host.llm.entity;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace LinkToolAddin.common;
|
|
|
|
public class HttpRequest
|
|
{
|
|
public static async Task<string> SendPostRequestAsync(string url, string jsonContent, string apiKey)
|
|
{
|
|
using var httpClient = new HttpClient();
|
|
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
|
|
var response = await httpClient.PostAsync(url, new StringContent(jsonContent, Encoding.UTF8, "application/json"));
|
|
response.EnsureSuccessStatusCode();
|
|
var responseBody = await response.Content.ReadAsStringAsync();
|
|
return responseBody;
|
|
}
|
|
} |