Question Details

No question body available.

Tags

c# .net dotnet-httpclient server-sent-events

Answers (1)

January 8, 2026 Score: 4 Rep: 1,156 Quality: Medium Completeness: 60%

The issue turned out to be caused by a missing Accept header on the client request.

When consuming an SSE endpoint from Blazor WebAssembly using HttpClient, the call to GetStreamAsync() will never complete unless the request explicitly declares that it accepts text/event-stream.

Without this header:

• The HTTP connection is opened
• The server starts streaming SSE frames
• But GetStreamAsync() never returns a stream and appears to hang forever

Adding the correct Accept header immediately fixes the issue.


✔ Fix

using var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("accept", "text/event-stream");
httpClient.DefaultRequestHeaders.Add("SessionId", SessionId.ToString());

var url = $"/ssehost/connect/{WebUtility.UrlEncode(ServiceId.Value)}"; using var stream = await httpClient.GetStreamAsync(url, Cts.Token);

After adding this header, the SSE stream becomes readable immediately and frames start arriving as expected.