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