'.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.
The service works fine when using IIS LocalHost but the client throws this exception when calling the remote server:
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. What am I doing wrong ?
Solution 1:[1]
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.
The code additions to client and server are explained in this article.
After making these changes/additions my gRPC messaging service is working fine. 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.
Solution 2:[2]
I had the same problem and I have sold it with grpc web as a reverse proxy. first of all you should install Grpc.Net.Client.Web on your grpc service project. after that, use middleware.
app.UseGrpcWeb();
then replace your MapGrpcService with this command.
endpoints.MapGrpcService<yourgRPCService>().EnableGrpcWeb();
in ConfigureService method, add bellow commands.
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.
Solution 3:[3]
@poury saved my life. This worked for me.
I have to update my client's code in ConfigureService method and add code below. (Required Grpc.Net.Client.Web package)
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(); on your Server's code.
PS: I don't know why, because my client's side is C# also, not a browser?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jon morgan |
| Solution 2 | Peter Csala |
| Solution 3 | nam.mai.dev |
