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