How to get ETag header in Blazor Web Assembly

Steve Wark 1 Reputation point
2020-12-23T21:53:38.58+00:00

I'm trying to get the ETag header for a PWA Blazor application I'm developing. I can see the API is returning the ETag header (can see in Fiddler and get the header in Postman) and I can use HTTPCLIENT in .netcore console application and get the value, but the same code implemented in the Blazor Web Assembly applications fails. The code snippet is below;

HttpClient client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e22SgnLJgnTmVEK1qMP4bohnzM8MzUnfeQdB-rL0uHw");
        Task<HttpResponseMessage> s = client.GetAsync("https://localhost:44338/api/headers/3");
        HttpResponseMessage nresponse2 = await s;
        var etag2 = nresponse2.Headers.FirstOrDefault(i => i.Key == "ETag").Value.FirstOrDefault();

On reviewing the project differences I see that the Console app is a .NET 5.0 and includes Microsoft.NETCore.app package while the Blazor Web Assembly app is also a .NET 5.0 but it includes Microsoft.AspNetCore.Components.WebAssembly (5.0.1), Microsoft.AspNetCore.Components.WebAssembly.DevServer (5.0.1) and System.Net.Json (5.0.0) packages.

Any advice on why the nresponse2 message being returned is different and how I might get this ETag value in the Blazor WASM app?

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,383 questions
{count} votes