Asp.net:不支持“application/grpc-web”

Ray*_*Ray 6 code-first grpc asp.net-core blazor grpc-web

我在浏览器上运行了 Asp.net core 和 gRPC...但现在我得到:

info: Grpc.AspNetCore.Server.ServerCallHandler[2]
  Request content-type of 'application/grpc-web' is not supported.
Run Code Online (Sandbox Code Playgroud)

关于如何追踪这个问题有什么想法吗?

tha*_*ker 16

可能是您的问题Startup.cs

你的应该看起来像这样 在此输入图像描述

我的猜测是您缺少app.UseGrpcWeb()EnabledGrpc()EndpointConventionBuilder


小智 7

我遇到了这个问题。我有我的app.UseGrpcWeb();以前app.UseRouting();

一定是在之后。

所以正确的顺序是:

    app.UseRouting();
    app.UseGrpcWeb();
Run Code Online (Sandbox Code Playgroud)

请参阅https://learn.microsoft.com/en-us/aspnet/core/grpc/browser?view=aspnetcore-5.0 --“在 ASP.NET Core 中配置 gRPC-Web