今天在編寫gRPC的集成測試的時候,運行出現以下錯誤
Grpc.Core.RpcException : Status(StatusCode="Internal", Detail="Bad gRPC response. Response protocol downgraded to HTTP/1.1.")
出現該問題的原因是請求的時候使用的是HTTP/2.0
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
但是在響應的時候卻是接收的HTTP/1.1,只要在接收的時候把Response的版本改為Request的版本一致就行了
response.Version = request.Version;