简体   繁体   English

HttpMessageResponse 在 Blazor WebAssembly 应用程序中没有内容

[英]HttpMessageResponse have no content in Blazor WebAssembly application

I have developed the Blazor WebAssembly.我开发了 Blazor WebAssembly。

On click I am executing HTTP POST as follows:单击时,我正在执行 HTTP POST,如下所示:

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 显示的那样,它似乎没问题 - 响应状态为 OK,并且有 186 字节的内容!

wireshark 显示有数据

however, in my Blazor Wasm application I got response with empty content...但是,在我的 Blazor Wasm 应用程序中,我得到了空内容的响应...

在此处输入图像描述

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?我设置了 CORS,也许我应该做些额外的事情?

Actually, the problem was about CORS, but not in my Blazor application, but in the server that hosts the Blazor Application.实际上,问题出在 CORS 上,但不是在我的 Blazor 应用程序中,而是在托管 Blazor 应用程序的服务器上。 It was necessary to include such an HTTP header in the response:有必要在响应中包含这样的 HTTP header :

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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