using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HttpClientStudy.Core.CustomHttpClient { /// <summary> /// Polly V8 /// 类型化客户端 /// </summary> public class Polly8ApiService { public HttpClient Client { get; set; } public Polly8ApiService(HttpClient httpClient) { Client = httpClient; } public async Task<string> Hello() { var content = await Client.GetStringAsync("/api/Polly8/Hello"); return content; } public async Task<string> Exception() { var response = await Client.GetAsync("/api/Polly8/Exception"); response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); return content; } public async Task<string> RetryException() { var response = await Client.GetAsync("/api/Polly8/RetryException"); response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); return content; } public async Task<string> RandomException() { var response = await Client.GetAsync("/api/Polly8/RandomException"); response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); return content; } public async Task<string> ToggleException() { var response = await Client.GetAsync("/api/Polly8/ToggleException?toggleId=" + Guid.NewGuid().ToString()); response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); return content; } } }