.Net Core GRPC报错

.Net Core GRPC报错

环境说明

报错内容

Grpc.Core.RpcException:“Status(StatusCode=Internal, Detail="Error starting gRPC call: An error occurred while sending the request.")”

解决办法

解决问题说明1
解决问题说明2
在客户端grpc请求之前加上AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
客户端代码如下

        static async Task Main(string[] args)
        {
            // The port number(5001) must match the port of the gRPC server.
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            using var channel = GrpcChannel.ForAddress("http://localhost:5001");
            var client = new Greeter.GreeterClient(channel);
            var reply = await client.SayHelloAsync(
                              new HelloRequest { Name = "GreeterClient" });
            Console.WriteLine("Greeting: " + reply.Message);
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }

建议:直接上.NET 5

上一篇:一款不错的 Go Server/API boilerplate,使用 K8S+DDD+CQRS+ES+gRPC 最佳实践构建


下一篇:gRPC 拦截器能做些什么?