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.
- 添加
到Blazor应用程序AppContext.SetSwitch(“System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport”,true)
(一开始,在调用builder之前)并使用Program.cs
服务.AddGrpcClient()代码>将我的服务客户端添加到DI
- 正在为我的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.
值得一提:
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)代码>从控制台应用程序工作
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上侦听。