[英]Blazor WebAssembly: The provided ContentType is not supported;
I have installed the Blazor WebAssembly Example Project (WeatherForecast) today by the following command line:我今天通过以下命令行安装了 Blazor WebAssembly 示例项目 (WeatherForecast):
dotnet new blazorwasm --hosted -o ProjectName
I started the SPA directly after the installation via Visual Studio 2019 in Debug Mode.我在调试模式下通过 Visual Studio 2019 安装后直接启动了 SPA。 The Browser is: Chrome.
浏览器是:Chrome。 The Browser shows the app, but when I select the Nav Menu "Fetch Data" then nothing happens.
浏览器显示应用程序,但是当我 select 导航菜单“获取数据”时,什么也没有发生。 Chrome shows 1 Error:
Chrome 显示 1 个错误:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: The provided ContentType is not supported; the supported types are 'application/json' and the structured syntax suffix 'application/+json'.
System.NotSupportedException: The provided ContentType is not supported; the supported types are 'application/json' and the structured syntax suffix 'application/+json'.
at System.Net.Http.Json.HttpContentJsonExtensions.ValidateContent (System.Net.Http.HttpContent content) <0x2e87f38 + 0x0009a> in <filename unknown>:0
at System.Net.Http.Json.HttpContentJsonExtensions.ReadFromJsonAsync[T] (System.Net.Http.HttpContent content, System.Text.Json.JsonSerializerOptions options, System.Threading.CancellationToken cancellationToken) <0x2e87d30 + 0x00006> in <filename unknown>:0
at System.Net.Http.Json.HttpClientJsonExtensions.GetFromJsonAsyncCore[T] (System.Threading.Tasks.Task`1[TResult] taskResponse, System.Text.Json.JsonSerializerOptions options, System.Threading.CancellationToken cancellationToken) <0x2e40838 + 0x0011c> in <filename unknown>:0
at BlazorIssue.Client.Pages.FetchData.OnInitializedAsync () [0x00033] in D:\Projects\BlazorIssue\Client\Pages\FetchData.razor:43
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x2b8cb98 + 0x0013a> in <filename unknown>:0
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) <0x2dd8340 + 0x000b6> in <filename unknown>:0
Chrome shows the following Request Headers: Chrome 显示以下请求标头:
Context-Information:上下文信息:
That is curious because a fresh installation of this example project worked yesterday with no problems.这很好奇,因为这个示例项目的全新安装昨天没有问题。
Although this isn't true for the OP, who's getting a "200 Ok" response, this can also happen if your API method returns null (mine was throwing a DB exception and returning null as a fallback).尽管这对于 OP 来说并非如此,他得到了“200 Ok”响应,但如果您的 API 方法返回 null(我的方法抛出 DB 异常并返回 null 作为后备),也会发生这种情况。
I had " 204 No Content " as the response and "The provided ContentType is not supported; the supported types are 'application/json' and the structured syntax suffix 'application/+json'."我有“ 204 No Content ”作为响应和“不支持提供的 ContentType;支持的类型是‘application/json’和结构化语法后缀‘application/+json’。” as the error at the client end.
作为客户端的错误。
I suppose null doesn't look like json:-)我想 null 看起来不像 json:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.