|
@@ -2,6 +2,7 @@
|
|
|
using System.Text;
|
|
|
using DataSharing.Share.Dtos.Province;
|
|
|
using IdentityModel.Client;
|
|
|
+using MediatR;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using XF.Domain.Dependency;
|
|
|
using XF.Domain.Exceptions;
|
|
@@ -48,25 +49,23 @@ public class BaseHttpInvoker : IHttpInvoker, IScopeDependency
|
|
|
return System.Text.Json.JsonSerializer.Deserialize<TResponse>(rsp);
|
|
|
}
|
|
|
|
|
|
- public async Task<TResponse?> RequestStringContentAsync<TRequest, TResponse>(TRequest request, Action<HttpClient>? setHttpClient = null,
|
|
|
- CancellationToken cancellationToken = default) where TRequest : ISharingStringRequest, new()
|
|
|
+ public async Task<TResponse?> RequestStringContentAsync<TResponse>(string url, string httpMethod, string? stringContent = null,
|
|
|
+ Action<HttpClient>? setHttpClient = null, CancellationToken cancellationToken = default)
|
|
|
{
|
|
|
var httpClient = _httpClientFactory.CreateClient();
|
|
|
|
|
|
if (setHttpClient != null)
|
|
|
setHttpClient.Invoke(httpClient);
|
|
|
|
|
|
- var url = request.GetRequestUrl();
|
|
|
- var method = request.GetHttpMethod();
|
|
|
var rsp = string.Empty;
|
|
|
- if (HttpMethods.IsGet(method))
|
|
|
+ if (HttpMethods.IsGet(httpMethod))
|
|
|
{
|
|
|
rsp = await httpClient.GetStringAsync(url, cancellationToken);
|
|
|
}
|
|
|
- else if (HttpMethods.IsPost(method))
|
|
|
+ else if (HttpMethods.IsPost(httpMethod))
|
|
|
{
|
|
|
- using var responseMessage = await httpClient.PostAsync(url,
|
|
|
- new StringContent(request.Content, Encoding.UTF8), cancellationToken);
|
|
|
+ using var responseMessage = await httpClient.PostAsync(url, new StringContent(stringContent, Encoding.UTF8),
|
|
|
+ cancellationToken);
|
|
|
responseMessage.EnsureSuccessStatusCode();
|
|
|
using var responseContent = responseMessage.Content;
|
|
|
rsp = await responseContent.ReadAsStringAsync(cancellationToken);
|