我正在尝试通过MagicOnion向我的服务器发出请求(它使用来自 gRPC 的传输,但使用不同的序列化协议,消息包而不是protobuf)。
一个小型测试客户端运行net5.0
如下:
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
var address = $"http://{ServerUrl.Host}:5002";
using var channel = GrpcChannel.ForAddress(address);
var myServiceClient = MagicOnionClient.Create<IMyService>(channel);
var result = await myServiceClient.GetMyData();
...并成功收到响应。但是,当我尝试在 Android 上执行完全相同的代码时,我在服务器日志中看到了这个错误:
Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2ConnectionErrorException: HTTP/2 connection error (PROTOCOL_ERROR): Invalid HTTP/2 connection preface.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ParsePreface(ReadOnlySequence`1& buffer, SequencePosition& consumed, SequencePosition& examined)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.TryReadPrefaceAsync()
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ProcessRequestsAsync[TContext](IHttpApplication`1 application)
根据日志和流量转储,很明显 .Net 5 上的客户端使用 .Net 5HTTP/2
和 Android - HTTP/1.1
. 据我了解,这是两个请求之间的唯一区别。
如何使 Android 上的客户端(API 30,monoandroid10)仍然使用HTTP/2
?