需要安装 httpx 依赖
import httpx
def check_http2_support(domain):
try:
with httpx.Client(http2=True) as client:
response = client.get(f"{domain}")
if response.http_version == "HTTP/2":
return True
else:
return False
except httpx.HTTPError:
return False
# Test if the domain supports HTTP/2.0
domain = input("请输入要检测的地址:")
supports_http2 = check_http2_support(domain)
if supports_http2:
print(f"{domain} 支持HTTP/2.0协议")
else:
print(f"{domain} 不支持HTTP/2.0协议")