It's really helpful. Unfortunately, I have not been able to add custom HTTP Headers to the request so far. Any suggestions;
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
DelegatingHandler
HttpClient
TraceLogHandler
internal class HeaderHandler : DelegatingHandler { protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { request.Headers.Add("X-MyHeader", "MyValue"); return base.SendAsync(request, cancellationToken); } }
Then in Startup.cs first register it
services.AddScoped<HeaderHandler>();
and then add it to the HttpClient setup e.g. before AddHeaderPropagation line
.AddHttpMessageHandler<HeaderHandler>()
Let me know if this is not what you had in mind or it doesn't work for your case.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
It's really helpful. Unfortunately, I have not been able to add custom HTTP Headers to the request so far. Any suggestions;
You can add them through additional
DelegatingHandler
which you would add to theHttpClient
setup. So, create something likeTraceLogHandler
and append a header.So, something like
Then in Startup.cs first register it
and then add it to the HttpClient setup e.g. before AddHeaderPropagation line
Let me know if this is not what you had in mind or it doesn't work for your case.