You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
939 B
C#

8 months ago
namespace HttpClientStudy.Core
8 months ago
{
/// <summary>
/// Http 错误处理
/// </summary>
public class HttpError
{
8 months ago
// 定义一个 HttpClient 实例,共享
public static HttpClient HttpClient = new HttpClient(new SocketsHttpHandler() { PooledConnectionLifetime = TimeSpan.FromMinutes(1) })
{
BaseAddress = new Uri(WebApiConfig.WebApiBaseUrl)
};
public async Task<HttpStatusCode> UrlNotFoundAsync()
{
var response = await HttpClient.GetAsync("http://www.notingxxxxxxxx.com/404.html");
response.EnsureSuccessStatusCode();
return response.StatusCode;
}
public async Task<HttpStatusCode> Http404Async()
{
var response = await HttpClient.GetAsync("http://www.baidu.com/404.html");
response.EnsureSuccessStatusCode();
return response.StatusCode;
}
8 months ago
}
}