简体   繁体   中英

HttpMessageResponse have no content in Blazor WebAssembly application

I have developed the Blazor WebAssembly.

On click I am executing HTTP POST as follows:

HttpClient httpClient = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, connectURl);
request.SetBrowserRequestMode(BrowserRequestMode.NoCors);
request.Content = new ByteArrayContent(contentBytes);
var response2 = await httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead);

And it seems to be ok, as Wireshark shows - the response is with OK status and have 186 bytes of content!

wireshark 显示有数据

however, in my Blazor Wasm application I got response with empty content...

在此处输入图像描述

Anyone can assume the reason? Anyone can point me to some phrase I can google it? I set CORS, maybe there is something I should do additionaly?

Actually, the problem was about CORS, but not in my Blazor application, but in the server that hosts the Blazor Application. It was necessary to include such an HTTP header in the response:

Headers.Add("Content-Type", "application/wasm");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM