gRPC call throws an exception: Status(StatusCode=Internal, Detail="Bad gRPC response. Response protocol downgraded to HTTP/1.1.")
See original GitHub issueI checked all “Closed” issues I could find. None of them helped.
What version of gRPC and what language are you using?
Using C# with Nuget packages: Grpc.Net.Client - 2.28.0 Grpc.Tools - 2.28.1 Google.Protobuf v3.11.4
What operating system (Linux, Windows,…) and version?
Windows 10 Pro
What runtime / compiler are you using (e.g. .NET Core SDK version dotnet --info
)
Microsoft Visual Studio Community 2019 Version 16.5.3 Building .Net Core 3.1 Console app
.NET Core SDK (reflecting any global.json): Version: 3.1.201 Commit: b1768b4ae7
Runtime Environment: OS Name: Windows OS Version: 10.0.18363 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.201\
Host (useful for support): Version: 3.1.3 Commit: 4a9f85e9f8
.NET Core SDKs installed: 3.1.201 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
What did you do?
Used different options to create a channel. It would be too much if I showed all options I tried with different SocketsHttpHandler and HttpClient and GrpcChannelOptions and HttpClientHandler. The basic code which should work is below.
static string username = "un";
static string password = "pp";
static byte[] data = Encoding.ASCII.GetBytes(username + ":" + password);
static string encodedCredentials = System.Convert.ToBase64String(data);
private static GrpcChannel CreateAuthenticatedChannel(string address)
{
//using CallCredentials and below SslCredentials
var credentials = CallCredentials.FromInterceptor((context, metadata) =>
{
metadata.Add("Authorization", $"Basic {encodedCredentials}");
metadata.Add("Content-Type", "UTF8");
//metadata.Add("ContentType", "UTF8");
//metadata.Add("User-Agent", "grpc-dotnet/2.25.0.0");
//metadata.Add("grpc-accept-encoding", "identity,gzip");
//metadata.Add("Content-Type", "application/grpc");
return Task.CompletedTask;
});
// SslCredentials is used here because this channel is using TLS.
var channel = GrpcChannel.ForAddress(address, new GrpcChannelOptions
{
Credentials = ChannelCredentials.Create(new SslCredentials(), credentials)
});
return channel;
}
Then call the service
var channel = CreateAuthenticatedChannel("https://mysite");
var client = new MyDbService.MyDbServiceClient(channel);
var result = client.usersearch(new UserSearch());
What did you expect to see?
Expect not to get an exception with Status(StatusCode=Internal, Detail=“Bad gRPC response. Response protocol downgraded to HTTP/1.1.”)
What did you see instead?
An exception
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Cannot accept that. I confirmed that server does support HTTP/2 and I am not sure what you mean by “intermediate” server. I cannot guarantee that every server on the way supports HTTP/2 which they should as they work as proxies. Unfortunately will not be able to use gRPC till it matures.
you can not configure it to use HTTP/2, because the connection downgrades to HTTP/1.1 thus it fails since gRPC only works with Http2