Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor WASM: HttpClient.SendAsync does not set the RequestMessage in ResponseMessage #42691

Closed
ealsur opened this issue Sep 24, 2020 · 3 comments · Fixed by #42822
Closed

Blazor WASM: HttpClient.SendAsync does not set the RequestMessage in ResponseMessage #42691

ealsur opened this issue Sep 24, 2020 · 3 comments · Fixed by #42822
Assignees
Labels
arch-wasm WebAssembly architecture area-System.Net.Http
Milestone

Comments

@ealsur
Copy link

ealsur commented Sep 24, 2020

Describe the bug

When SendAsync is called on HttpClient, the HttpResponseMessage.RequestMessage is null when the HttpClient is in Blazor WASM, but not null (and equal to the original HttpRequestMessage) on NET Core.

In NET Core, we do:

HttpClient httpclient = new HttpClient();
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "https://www.bing.com");
HttpResponseMessage responseMessage = await httpclient.SendAsync(
    requestMessage,
    HttpCompletionOption.ResponseHeadersRead);

In Blazor WASM, we have the HttpClient registered as:

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

And in a Blazor page:

@inject HttpClient Http

HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "https://localhost:44384/");
HttpResponseMessage responseMessage = await Http.SendAsync(
    requestMessage,
    HttpCompletionOption.ResponseHeadersRead);

To Reproduce

Sample code in this repo: https://github.com/ealsur/httpclientwasm

Running the Console app, the output is:

https://github.com/ealsur/httpclientwasm/blob/master/ConsoleApp/Program.cs#L19

image

Running the Blazor WASM app and browsing to Fetch Data, shows the output in the Browser Console:

https://github.com/ealsur/httpclientwasm/blob/master/Blazor/Pages/FetchData.razor#L48

image

@pranavkm pranavkm transferred this issue from dotnet/aspnetcore Sep 24, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Net.Http untriaged New issue has not been triaged by the area owner labels Sep 24, 2020
@ghost
Copy link

ghost commented Sep 24, 2020

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@pranavkm
Copy link
Contributor

FYI @kjpou1

@lewing lewing added the arch-wasm WebAssembly architecture label Sep 28, 2020
@lewing lewing added this to the 5.0.0 milestone Sep 28, 2020
@lewing lewing removed the untriaged New issue has not been triaged by the area owner label Sep 28, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
@karelz
Copy link
Member

karelz commented Jan 26, 2021

Fixed in 6.0/master (PR #42822) and in 5.0 (PR #42849).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-System.Net.Http
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants