【Azure App Service】验证App Service接受HTTP 2.0请求

简介: 【Azure App Service】验证App Service接受HTTP 2.0请求

问题描述

在App Service中启用了HTTP 2.0后,如何来验证它可以正常接受HTTP 2.0的请求呢?

问题解答

如果直接使用浏览器访问,无法直接判断出来是否使用 HTTP 2.0,所以本文中使用.NET Console代码来测试HTTP 2.0.

第一步:打开Visual Studio 2022,创建一个.NET Console Application

第二步:添加 HttpClient() 代码,并设置 HttpRequestMessage 的 Version 为2.0

Console.WriteLine("Hello, World!");
var client = new HttpClient() { BaseAddress = new Uri("https://lbphptest01.chinacloudsites.cn/") };
Console.WriteLine("Sending HTTP 2.0 Request.");
// HTTP/2 request
using (var request = new HttpRequestMessage(HttpMethod.Get, "/") { Version = new Version(2, 0) })
using (var response = await client.SendAsync(request))
Console.WriteLine(response);

注意:也可以直接指定 HTTPClient 类 DefaultRequestVersion 属性值

var SecondRequest = new HttpClient()
{
    BaseAddress = new Uri("https://lbphptest01.chinacloudsites.cn/"),
    DefaultRequestVersion = new Version(2, 0)
};
// HTTP/2 is default
using (var response = await SecondRequest.GetAsync("/"))
    Console.WriteLine(response);

 

第三步:运行代码,查看结果 HttpResponse Version 为2.0

 

附录:示例代码

// .NET Console App的代码使用的.NET 8 Framework并且使用顶级语句(top-level statements)
Console.WriteLine("Hello, World!");
var client = new HttpClient() { BaseAddress = new Uri("https://xxx.chinacloudsites.cn/") };
Console.WriteLine("#1: Sending HTTP 2.0 Request By HttpRequestMessage Version");
// HTTP/2 request
using (var request = new HttpRequestMessage(HttpMethod.Get, "/") { Version = new Version(2, 0) })
using (var response = await client.SendAsync(request))
Console.WriteLine(response);
Console.WriteLine("#2: Sending HTTP 2.0 Request By HttpClient DefaultRequestVersion");
var SecondRequest = new HttpClient()
{
    BaseAddress = new Uri("https://xxx.chinacloudsites.cn/"),
    DefaultRequestVersion = new Version(2, 0)
};
// HTTP/2 is default
using (var response = await SecondRequest.GetAsync("/"))
    Console.WriteLine(response);
Console.Read();

 

参考资料

Send HTTP 2.0 Request to App Service using C# : https://techcommunity.microsoft.com/t5/apps-on-azure-blog/send-http-2-0-request-to-app-service-using-c/ba-p/4034469

HttpClient Class:https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-8.0

HttpClient.DefaultRequestVersion Property : https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.defaultrequestversion?view=net-8.0#system-net-http-httpclient-defaultrequestversion

 

 

相关文章
|
25天前
|
应用服务中间件 Linux nginx
【Azure App Service】基于Linux创建的App Service是否可以主动升级内置的Nginx版本呢?
基于Linux创建的App Service是否可以主动升级内置的Nginx版本呢?Web App Linux 默认使用的 Nginx 版本是由平台预定义的,无法更改这个版本。
134 77
|
29天前
|
C#
【Azure Function】Function App出现System.IO.FileNotFoundException异常
Exception while executing function: xxxxxxx,The type initializer for 'xxxxxx.Storage.Adls2.StoreDataLakeGen2Reading' threw an exception. Could not load file or assembly 'Microsoft.Extensions.Configuration, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the
115 64
|
1月前
|
监控 关系型数据库 MySQL
|
16天前
|
API 数据安全/隐私保护
Haskell中的HTTP请求:代理与响应状态检查
Haskell中的HTTP请求:代理与响应状态检查
|
14天前
|
JavaScript API
【Azure Function】Function App门户上的Test/Run返回错误:Failed to fetch
Running your function in portal requires the app to explicitly accept requests from https://portal.azure.cn. This is known as cross-origin resource sharing (CORS).Configure CORS to add https://portal.azure.cn to allowed origins.
|
1月前
|
Windows
【Azure App Service】对App Service中CPU指标数据中系统占用部分(System CPU)的解释
在Azure App Service中,CPU占比可在App Service Plan级别查看整个实例的资源使用情况。具体应用中仅能查看CPU时间,需通过公式【CPU Time / (CPU核数 * 60)】估算占比。CPU百分比适用于可横向扩展的计划(Basic、Standard、Premium),而CPU时间适用于Free或Shared计划。然而,CPU Percentage包含所有应用及系统占用的CPU,高CPU指标可能由系统而非应用请求引起。详细分析每个进程的CPU占用需抓取Windows Performance Trace数据。
100 40
|
1月前
|
缓存 应用服务中间件 Apache
HTTP 范围Range请求
HTTP范围请求是一种强大的技术,允许客户端请求资源的部分内容,提高了传输效率和用户体验。通过正确配置服务器和实现范围请求,可以在视频流、断点续传下载等场景中发挥重要作用。希望本文提供的详细介绍和示例代码能帮助您更好地理解和应用这一技术。
111 19
|
2月前
|
JSON 数据格式
.net HTTP请求类封装
`HttpRequestHelper` 是一个用于简化 HTTP 请求的辅助类,支持发送 GET 和 POST 请求。它使用 `HttpClient` 发起请求,并通过 `Newtonsoft.Json` 处理 JSON 数据。示例展示了如何使用该类发送请求并处理响应。注意事项包括:简单的错误处理、需安装 `Newtonsoft.Json` 依赖,以及建议重用 `HttpClient` 实例以优化性能。
92 2
|
Web App开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
TCP洪水攻击(SYN Flood)的诊断和处理 Posted by  海涛  on 2013 年 7 月 11 日 Tweet1 ​1. SYN Flood介绍 前段时间网站被攻击多次,其中最猛烈的就是TCP洪水攻击,即SYN Flood。
1021 0
|
Web App开发 新零售 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
1.尽可能地了解需求,系统层面适用开闭原则 2.模块化,低耦合,能快速响应变化,也可以避免一个子系统的问题波及整个大系统 3.
769 0

热门文章

最新文章

  • 1
    iOS|记一名 iOS 开发新手的前两次 App 审核经历
    10
  • 2
    2025同城线下陪玩APP开发/电竞游戏平台搭建游戏陪玩APP源码/语音APP开发
    17
  • 3
    flutter3-wetrip跨平台自研仿携程app预约酒店系统模板
    25
  • 4
    通过外部链接启动 Flutter App(详细介绍及示例)
    21
  • 5
    【03】仿站技术之python技术,看完学会再也不用去购买收费工具了-修改整体页面做好安卓下载发给客户-并且开始提交网站公安备案-作为APP下载落地页文娱产品一定要备案-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
    55
  • 6
    【02】仿站技术之python技术,看完学会再也不用去购买收费工具了-本次找了小影-感觉页面很好看-本次是爬取vue需要用到Puppeteer库用node.js扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
    46
  • 7
    【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
    40
  • 8
    【Azure Function】Function App门户上的Test/Run返回错误:Failed to fetch
    36
  • 9
    小游戏源码开发之可跨app软件对接是如何设计和开发的
    42
  • 10
    原生鸿蒙版小艺APP接入DeepSeek-R1,为HarmonyOS应用开发注入新活力
    178