My client code makes call to an API and I'm trying to get the returned ETag value from the response headers. If I use Fiddler I can see the response contains the ETag header and if I make API call using Postman I can see the ETag header, but no matter what approach I take to try and retrieve the headers in my code all I get returned is a null.
Essentially the API call is;
// create request object
var request = new HttpRequestMessage(HttpMethod.Get, url);
// add authorization header
request.Headers.Authorization = new AuthenticationHeaderValue("bearer", await GetBearerToken());
// send request
HttpResponseMessage response = await _client.SendAsync(request);
Fiddler Response Header showing Etag
The Postman response is;
I've spent hours searching and trying examples from web, but no matter what I try I can't get the the ETag header.
Using the example code below I do get the first 2 headers as shown in the Postman response headers returned but not the ETag header / value.
String allResponseHeaders = Enumerable
.Empty<(String name, String value)>()
.Concat(
response.Headers
.SelectMany(kvp => kvp.Value
.Select(v => (name: kvp.Key, value: v))
))
.Concat(
response.Content.Headers
.SelectMany(kvp => kvp.Value
.Select(v => (name: kvp.Key, value: v))
))
.Aggregate(
seed: new StringBuilder(),
func: (sb, pair) => sb.Append(pair.name).Append(": ").Append(pair.value).AppendLine(),
resultSelector: sb => sb.ToString()
);
I'm using Visual Studio, Blazor and aspnetcore 5.0 and I'm looking to generate an PWA with IndexDB and use ETag's to reduce data downloads.
Any help on how to get to the Etag header will be much appreciated...