You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Windows 7上为ASP.NET Core Web应用启用HTTP/2?

Windows 7 下 ASP.NET Core 5.0 调用 Google API 的 HTTP/2 错误解决办法

1. 强制客户端请求使用 HTTP/1.1

Windows 7 上 Kestrel 不支持 HTTP/2 是系统级限制,最直接的解决方式是让调用 Google API 的请求强制使用 HTTP/1.1。在创建 HttpClient 时明确指定版本和策略:

var httpClient = new HttpClient
{
    DefaultRequestVersion = HttpVersion.Version11,
    DefaultVersionPolicy = HttpVersionPolicy.RequestVersionExact
};

// 示例调用Google API
var apiResponse = await httpClient.GetAsync("你的Google API接口地址");

Google API 完全兼容 HTTP/1.1,这样就能绕过 HTTP/2 版本不兼容的问题。

2. 调整 Kestrel 服务端协议配置

如果项目中 Kestrel 配置了强制启用 HTTP/2,需要修改配置文件(appsettings.json),限制服务端仅使用 HTTP/1:

"Kestrel": {
  "Endpoints": {
    "Http": {
      "Url": "http://localhost:5000",
      "Protocols": "Http1"
    },
    "Https": {
      "Url": "https://localhost:5001",
      "Protocols": "Http1"
    }
  }
}

避免服务端尝试启用 HTTP/2 引发的连锁问题。

3. 长期解决方案:升级系统到 Windows 10+

Windows 7 已停止官方支持,且 .NET 5 及后续版本对 Win7 的兼容性有限。如果条件允许,升级到 Windows 10 或更高版本,Kestrel 就能原生支持 HTTP/2,从根源上解决这类系统级兼容性问题。

内容的提问来源于stack exchange,提问作者Bryant

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 20:43:15