[英].net Grpc Request protocol 'HTTP/1.1' is not supported
I've implemented a simple gRPC service in.net5 similar to the GreeterService in the project template.我在 .net5 中实现了一个简单的 gRPC 服务,类似于项目模板中的 GreeterService。
The service works fine when using IIS LocalHost but the client throws this exception when calling the remote server:使用 IIS LocalHost 时服务工作正常,但客户端在调用远程服务器时抛出此异常:
Grpc.Core.RpcException HResult=0x80131500 Message=Status(StatusCode="Internal", Detail="Request protocol 'HTTP/1.1' is not supported.")
I thought Grpc used HTTP/2 by default.我以为 Grpc 默认使用 HTTP/2。 What am I doing wrong?
我究竟做错了什么?
I had the same problem and I have sold it with grpc web as a reverse proxy.我有同样的问题,我已经用 grpc web 作为反向代理出售了它。 first of all you should install Grpc.Net.Client.Web on your grpc service project.
首先你应该在你的 grpc 服务项目上安装 Grpc.Net.Client.Web。 after that, use middleware.
之后,使用中间件。
app.UseGrpcWeb();
then replace your MapGrpcService with this command.然后用这个命令替换你的 MapGrpcService 。
endpoints.MapGrpcService<yourgRPCService>().EnableGrpcWeb();
in ConfigureService method, add bellow commands.在 ConfigureService 方法中,添加以下命令。
var handler = new GrpcWebHandler(GrpcWebMode.GrpcWebText, new
HttpClientHandler());
services.AddGrpcClient<YourService.YourServiceClient>(options =>
{
options.Address = new Uri("http://YourServerAddress");
}).ConfigureChannel(o=> {
o.HttpClient = new HttpClient(handler);
});
now you should inject your grpc service client and call your method.现在你应该注入你的 grpc 服务客户端并调用你的方法。
Thanks for the responses.感谢您的回复。 After reading this article I realized I needed to add the Grpc-Web proxy to my app, as this translates an HTTP/1.1 client message to HTTP/2.
阅读本文后,我意识到我需要将 Grpc-Web 代理添加到我的应用程序中,因为这会将 HTTP/1.1 客户端消息转换为 HTTP/2。
The code additions to client and server are explained in this article . 本文解释了客户端和服务器的代码添加。
After making these changes/additions my gRPC messaging service is working fine.进行这些更改/添加后,我的 gRPC 消息传递服务工作正常。 Importantly - I spent a lot of time trying to figure out how to reference certificates in my call options - but the messaging works fine without a certificate.
重要的是——我花了很多时间试图弄清楚如何在我的看涨期权中引用证书——但是没有证书,消息传递也能正常工作。
@poury saved my life. @poury 救了我的命。 This worked for me.
这对我有用。 I have to update my client's code in ConfigureService method and add code below.
我必须在 ConfigureService 方法中更新我的客户端代码并在下面添加代码。 (Required
Grpc.Net.Client.Web
package) (需要
Grpc.Net.Client.Web
包)
services.AddGrpcClient<GreeterService.GreeterServiceClient>(o => { o.Address = new Uri("https://localhost:5001");})
.ConfigureChannel( o =>
{
o.HttpHandler = new GrpcWebHandler(new HttpClientHandler());
});
Also enabled app.UseGrpcWeb()
& endpoints.MapGrpcService<GreeterService>().EnableGrpcWeb();
还启用
app.UseGrpcWeb()
& endpoints.MapGrpcService<GreeterService>().EnableGrpcWeb();
on your Server's code.在您的服务器代码上。
PS: I don't know why, because my client's side is C# also, not a browser? PS:不知道为什么,因为我客户端也是C#,不是浏览器?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.