DEV Community


Discussion on: Make SOAP requests using IHttpClientFactory in .NET Core

nikolicbojan profile image
Bojan Nikolić Author

You can add them through additional DelegatingHandler which you would add to the HttpClient setup. So, create something like TraceLogHandler and append a header.
So, something like

internal class HeaderHandler : DelegatingHandler
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        request.Headers.Add("X-MyHeader", "MyValue");

        return base.SendAsync(request, cancellationToken);
Enter fullscreen mode Exit fullscreen mode

Then in Startup.cs first register it

Enter fullscreen mode Exit fullscreen mode

and then add it to the HttpClient setup e.g. before AddHeaderPropagation line

Enter fullscreen mode Exit fullscreen mode

Let me know if this is not what you had in mind or it doesn't work for your case.

Forem Open with the Forem app