最近学习grpc工具的时候遇到一个问题,创建好服务端和客户端,并成功运行后,遇到以下异常信息
io.netty.handler.codec.http2.Http2Exception: HTTP/2 client preface string missing or corrupt.
在StackOverflow找到解决方案
ManagedChannelBuilder
.forAddress("10.0.2.2", 50051)
.usePlaintext()
.build();
即创建ManagedChannel的时候,设置usePlaintext属性,根据文档,这个属性是指
* Use of a plaintext connection to the server. By default a secure connection mechanism
* such as TLS will be used.