小编val*_*asm的帖子

如何在 Xamarin.Forms 上调用 HTTP2

带有 .Net Standart 2.0 的 Xamarin.Forms 的 gRpc 在 http2 上工作,因此它应该是进行 HttpClient 调用或重用现有 gRpc 功能的某种方式。可能是我错过了一些东西。

重现问题的示例应用程序。您需要在某处托管 gRpc 服务。WebClient 调用在 AboutPage.xaml.cs aslo 测试项目中,在 web 文件夹中使用 asp core 3.1。 XamarinHttp2WithBackend GitHub

Fallowing 说明Microsoft.com - HttpClient Stack and SSL/TLS Implementation Selector for Android and Stackoverflow.com - 在 .Net 中使用 HTTP 2 和 HttpClient 也没有帮助。

对于 Asp Core 3.1 控制台应用程序,您可以执行(如下)并且可以工作。它不适用于 2.2 及更低版本

AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

var client = new HttpClient();
var req = new HttpRequestMessage(HttpMethod.Get, $"http://123.123.123.123:1234/ping/")
{
    Version = new Version(2, 0),
}; …
Run Code Online (Sandbox Code Playgroud)

c# android xamarin http2

9
推荐指数
1
解决办法
966
查看次数

标签 统计

android ×1

c# ×1

http2 ×1

xamarin ×1