|
|
|
@ -18,12 +18,16 @@ namespace HttpClientStudy.Core
|
|
|
|
|
/// <item>
|
|
|
|
|
/// <term>Try Catch 方式</term>
|
|
|
|
|
/// <description>(适用外部)</description>
|
|
|
|
|
/// </item>
|
|
|
|
|
/// <item>
|
|
|
|
|
/// <term>使用 Polly 类库</term>
|
|
|
|
|
/// <description>(更多功能)</description>
|
|
|
|
|
/// </item>
|
|
|
|
|
/// </list>
|
|
|
|
|
/// </item>
|
|
|
|
|
/// <item>
|
|
|
|
|
/// <term>HttpClient 管道</term>
|
|
|
|
|
/// <description>(统一处理)</description>
|
|
|
|
|
/// </item>
|
|
|
|
|
/// <item>
|
|
|
|
|
/// <term>使用 Polly 类库</term>
|
|
|
|
|
/// <description>(更多功能,也可结合HttpClient管道)</description>
|
|
|
|
|
/// </item>
|
|
|
|
|
/// </list>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// 简化处理
|
|
|
|
@ -47,6 +51,27 @@ namespace HttpClientStudy.Core
|
|
|
|
|
return response.StatusCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 没有服务(WebApi服务未启动)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<HttpStatusCode> NoServiceAsync()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = await HttpClient.GetAsync("http://localhost:30");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
// 捕获异常,处理
|
|
|
|
|
await Console.Out.WriteLineAsync(ex.Message );
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return HttpStatusCode.OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 404错误
|
|
|
|
|
/// </summary>
|
|
|
|
|