这是我用于消费get请求的代码。它运行良好,但是我想用polt封装HttpClientFactory,以便在异步过程中跟踪超时或网络故障。我该怎么办?
public static async Task<CustomerResponse> GetCustomersAsync(IQueryCritera critera)
{
if (critera == null)
{
throw new ArgumentNullException(nameof(critera));
}
var parmeters = new List<string>
{
"request.active=false"
};
if (!string.IsNullOrWhiteSpace(critera.SearchText))
{
parmeters.Add($"request.filter={critera.SearchString}");
}
var builder = new UriBuilder(GetApiUri());
builder.Path += "Customers/GetCustomers";
builder.Query = string.Join("&", parmeters);
var client = new HttpClient()
{
BaseAddress = GetBaseAddr();
};
using (var response = await client.GetAsync(builder.Uri).ConfigureAwait(false))
{
var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var result = JsonConvert.DeserializeObject<CustomerResponse>(responseText);
}
}