response.Headers.Remove(“Server”)没有从响应中删除Server标头,仍然获得“Server - > Microsoft-HTTPAPI / 2.0”
public class CustomHeaderHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
return base.SendAsync(request, cancellationToken)
.ContinueWith((task) =>
{
HttpResponseMessage response = task.Result;
response.Headers.Remove("Server");
return response;
});
}
}