如何解决从服务器端Blazor调用gRPC服务时如何实施HTTP而不是HTTPS
好的,长话短说:
- 我有Blazor服务器端应用程序。
- 我有gRPC服务
- 两者都在本地主机上运行
问题:
- 我无法使其通过HTTP连接(尽管HTTPS可以使用自签名证书)
我尝试过的事情:
- 正在添加
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport",true);
到Blazor应用Program.cs
(从一开始,在调用构建器之前),然后使用services.AddGrpcClient<>();
将我的服务客户端添加到DI - 在创建客户端之前,为我的gRPC服务创建客户端库(包装器)并将其添加到构造函数中:
public Client(string url)
{
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport",true);
_channel = GrpcChannel.ForAddress(url);
_client = new SvcTrlClient(_channel);
}
并将其自己注册到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.
值得一提的:
-
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>();
});
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。