gRPC使用HTTP2传输,当netcore 调用时默认是使用ssl加密.如果不方便部署ssl站点,或者不想在代码中使用https调用。可在调用RPC服务之前声明:
#增加代码,如果是内网调用,可不关注https
if (!SERVER_GRPC.StartsWith("https"))
{
AppContext.SetSwitch(
"System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
}
完整测试代码
private const string SERVER_GRPC = "http://192.168.0.238:5009";
public static async Task Main()
{
#去掉https支持关键代码
if (!SERVER_GRPC.StartsWith("https"))
{
AppContext.SetSwitch(
"System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
}
//1.声明客户端
var channel = GrpcChannel.ForAddress(SERVER_GRPC);
var searchClient = new SearchSvc.SearchSvcClient(channel);
var response=searchClient.Search(new SearchRequest() { Keywords = "test" });
}
本文介绍如何在不使用SSL的情况下,通过netcore调用gRPC服务。主要讲解了如何设置System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport为true,以支持HTTP2的非加密连接。
1829

被折叠的 条评论
为什么被折叠?



