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.

26 lines
748 B
C#

6 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HttpClientStudy.Core
{
/// <summary>
/// 默认处理器1 - 添加自定义请求头
/// </summary>
public class CustomHeadersHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
// 在请求中添加自定义头部
request.Headers.Add("X-Custom-Header", "CustomValue");
// 调用管道中的下一个处理器
return await base.SendAsync(request, cancellationToken);
//响应信息(可不处理)
}
}
}