|
|
@ -13,18 +13,18 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost |
|
|
|
|
|
|
|
public class HttpClientInvoker<TInput, TOutput> : IHttpClientInvoker<TInput, TOutput> |
|
|
|
{ |
|
|
|
// private readonly HttpAuthorizationHandler _httpAuthorizationHandler;
|
|
|
|
private readonly HttpAuthorizationHandler _httpAuthorizationHandler; |
|
|
|
private readonly string _baseUrl; |
|
|
|
|
|
|
|
|
|
|
|
public HttpClientInvoker(IConfiguration configuration |
|
|
|
// , HttpAuthorizationHandler httpAuthorizationHandler
|
|
|
|
, HttpAuthorizationHandler httpAuthorizationHandler |
|
|
|
) |
|
|
|
{ |
|
|
|
// _httpAuthorizationHandler = httpAuthorizationHandler;
|
|
|
|
_httpAuthorizationHandler = httpAuthorizationHandler; |
|
|
|
_baseUrl = configuration["RemoteServices:Default:BaseUrl"]; |
|
|
|
} |
|
|
|
public async Task<TOutput?> InvokeGetAsync(string routeString) |
|
|
|
public async Task<TOutput> InvokeGetAsync(string routeString) |
|
|
|
{ |
|
|
|
var client = CreateClient(); |
|
|
|
var response = await client.GetAsync(routeString); |
|
|
@ -33,11 +33,13 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost |
|
|
|
return dto; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<TOutput?> InvokePostAsync(TInput input, string routeString) |
|
|
|
public async Task<TOutput> InvokePostAsync(TInput input, string routeString) |
|
|
|
{ |
|
|
|
var client = CreateClient(); |
|
|
|
var response = await client.PostAsJsonAsync(routeString, input); |
|
|
|
response.EnsureSuccessStatusCode(); |
|
|
|
var str =await response.Content.ReadAsStringAsync(); |
|
|
|
|
|
|
|
var dto = await response.Content.ReadFromJsonAsync<TOutput>(); |
|
|
|
return dto; |
|
|
|
} |
|
|
@ -50,11 +52,11 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost |
|
|
|
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); |
|
|
|
|
|
|
|
//XmlHost也使用Jwt认证,并连到同一个IDS4 server,不需要再手工添加鉴权信息了
|
|
|
|
// if (_httpAuthorizationHandler.IsLoggedIn())
|
|
|
|
// {
|
|
|
|
// client.DefaultRequestHeaders.Authorization =
|
|
|
|
// new AuthenticationHeaderValue("Bearer", _httpAuthorizationHandler.GetCurrentBearer());
|
|
|
|
// }
|
|
|
|
if (_httpAuthorizationHandler.IsLoggedIn()) |
|
|
|
{ |
|
|
|
client.DefaultRequestHeaders.Authorization = |
|
|
|
new AuthenticationHeaderValue("Bearer", _httpAuthorizationHandler.GetCurrentBearer()); |
|
|
|
} |
|
|
|
|
|
|
|
return client; |
|
|
|
} |
|
|
|