Asp.net core 如何在从服务器端Blazor调用gRPC服务时强制使用HTTP(而不是HTTPS)

Asp.net core 如何在从服务器端Blazor调用gRPC服务时强制使用HTTP(而不是HTTPS),asp.net-core,.net-core,blazor,grpc,blazor-server-side,Asp.net Core,.net Core,Blazor,Grpc,Blazor Server Side,好吧,长话短说: Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: An error occurred while sending the request. IOException: The response ended prematurely.", DebugException=&quo

好吧,长话短说

Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: An error occurred while sending the request. IOException: The response ended prematurely.", DebugException="System.Net.Http.HttpRequestException: An error occurred while sending the request.
 ---> System.IO.IOException: The response ended prematurely.
  • 我有Blazor服务器端应用程序
  • 我有gRPC服务
  • 两者都在本地主机上运行
问题

Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: An error occurred while sending the request. IOException: The response ended prematurely.", DebugException="System.Net.Http.HttpRequestException: An error occurred while sending the request.
 ---> System.IO.IOException: The response ended prematurely.
  • 我无法使其通过HTTP连接(尽管HTTPS可以工作,使用自签名证书)
我所尝试的

Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: An error occurred while sending the request. IOException: The response ended prematurely.", DebugException="System.Net.Http.HttpRequestException: An error occurred while sending the request.
 ---> System.IO.IOException: The response ended prematurely.
  • 添加
    AppContext.SetSwitch(“System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport”,true)
    到Blazor应用程序
    Program.cs
    (一开始,在调用builder之前)并使用
    服务.AddGrpcClient()将我的服务客户端添加到DI
  • 正在为我的gRPC服务创建客户端库(包装器),并在构造函数中添加相同的内容,然后再创建客户端:
并亲自将其注册到Blazor应用程序的DI

我从Blazor打电话时得到的信息

Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: An error occurred while sending the request. IOException: The response ended prematurely.", DebugException="System.Net.Http.HttpRequestException: An error occurred while sending the request.
 ---> System.IO.IOException: The response ended prematurely.
值得一提

Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: An error occurred while sending the request. IOException: The response ended prematurely.", DebugException="System.Net.Http.HttpRequestException: An error occurred while sending the request.
 ---> System.IO.IOException: The response ended prematurely.
  • AppContext.SetSwitch(“System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport”,true)从控制台应用程序工作
这足以在gRPC端禁用HTTPS吗?

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)

        .UseSerilog()
        .UseWindowsService()

        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseKestrel(options =>
            {
                options.Listen(IPAddress.Loopback, 5666, x => x.Protocols = HttpProtocols.Http2);
            });

            webBuilder.UseStartup<Startup>();
        });
    }
}
公共静态IHostBuilder CreateHostBuilder(字符串[]args)=>
Host.CreateDefaultBuilder(args)
.useserlog()
.UseWindowsService()
.ConfigureWebHostDefaults(webBuilder=>
{
webBuilder.UseKestrel(选项=>
{
options.Listen(IPAddress.Loopback,5666,x=>x.Protocols=HttpProtocols.Http2);
});
webBuilder.UseStartup();
});
}
}

在启动配置中禁用Https重定向在哪一端?Blazor还是gRPC?gRPC仅在HTTP(端口5000)上侦听。它应该在gRPC侧。我已更新帖子。另外,我已经从启动选项json中删除了https url。当服务启动时-它不在HTTPS上侦听。