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.
29 lines
855 B
C#
29 lines
855 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace HttpClientStudy.Core
|
|
{
|
|
/// <summary>
|
|
/// 默认处理器1 - 简单的日志记录
|
|
/// </summary>
|
|
public class LoggingHandler : DelegatingHandler
|
|
{
|
|
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
|
{
|
|
// 记录请求信息
|
|
Console.WriteLine($"Request: {request.Method} {request.RequestUri}");
|
|
|
|
// 调用管道中的下一个处理器,并获取响应
|
|
var response = await base.SendAsync(request, cancellationToken);
|
|
|
|
// 记录响应信息
|
|
Console.WriteLine($"Response: {response.StatusCode}");
|
|
|
|
return response;
|
|
}
|
|
}
|
|
}
|