【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

 

 

相关文章
|
2月前
|
存储 安全 数据安全/隐私保护
【Azure Function App】在Function App中使用System Managed Identity访问Storage Account
本文介绍了如何在Azure Function中使用托管身份(Managed Identity)替代AzureWebJobsStorage连接函数应用到存储账户,以提高安全性并减少Access Key的使用。具体步骤包括:1) 启用系统分配的身份;2) 为函数应用授予存储访问权限,添加必要角色(如Storage Blob Data Contributor);3) 配置`AzureWebJobsStorage__blobServiceUri`参数指定Blob Service Uri。完成后删除旧配置,即可通过Managed Identity访问Storage Account。
110 20
|
26天前
|
安全 Linux 开发工具
【Azure Function】分享把Function App从.NET 6.0升级到.NET 8.0 Isolated的步骤
本文介绍了将Azure Function App从.NET 6.0升级到.NET 8.0 Isolated的步骤。.NET 6.0作为长期支持版本,生命周期至2024年11月结束。为确保持续支持,建议升级至更新版本。升级步骤包括安装.NET 8 SDK、更新Azure Functions Core Tools、修改项目文件目标框架为net8.0、更新兼容的NuGet包、本地测试以及重新发布到Azure。更多详细信息可参考官方文档。
|
27天前
|
域名解析 网络协议 网络安全
SSL证书验证全攻略:DNS/HTTP/手动解析怎么选?
SSL证书在网络安全中至关重要,1Panel提供三种验证方式:DNS验证、HTTP验证和手动解析。DNS验证便捷,适合CDN网站;HTTP验证快速,需服务器在线;手动解析灵活,但操作复杂。根据需求选择合适确认方式,定期检查证书状态。
269 2
|
1月前
|
API Go 网络架构
【Azure Logic App】特殊的方法来停止正常步骤无法停止的Workflow Job
本文介绍了一种特殊方法,用于解决标准版Logic App在异常情况下无法正常停止的问题。当点击Cancel按钮报错“WorkflowRunCanNotBeCancelled”时,可通过以下步骤解决:进入Logic App的Kudu页面,定位到`C:\home\site\wwwroot`目录下的`host.json`文件,添加`Jobs.SuspendedJobPartition`和`Jobs.CleanupJobPartition`参数,并以大写格式设置值为`"<WORKFLOWID>:2D<RUNID>"`。调整后可成功停止异常Job
79 18
|
1月前
|
测试技术 Linux 网络安全
【App Services】App Service报错远程证书无效 - "The remote certificate is invalid according to the validation procedure"
在开发环境中,新部署的应用(App Service)无法与 Salesforce 的远程端点建立 SSL/TLS 连接,报错显示证书无效。经分析,防火墙启用了 SSL Inspection,插入了私有 CA 签发的中间证书,导致 App Service 无法验证。解决方案包括禁用 SSL Inspection、设置 `WEBSITE_LOAD_ROOT_CERTIFICATES` 环境变量或临时禁用代码中的 SSL 验证(仅限测试环境)。
|
2月前
【Logic App】获取Azure Logic App在执行的标识值 Identifier
本文介绍了如何在Logic App中记录执行标识符以方便问题排查。通过添加一个变量(如RequestTrackingID),将其值设为`workflow()['run']['name']`,可实现将Logic App执行的Identifier与业务数据关联。这样,在排查问题时,可通过日志中的关键信息快速定位对应的Logic App执行记录,提升效率。文中还提供了操作步骤及参考资料,帮助用户更好地理解和实现该方法。
77 10
|
2月前
|
存储 监控 API
【Azure App Service】分享使用Python Code获取App Service的服务器日志记录管理配置信息
本文介绍了如何通过Python代码获取App Service中“Web服务器日志记录”的配置状态。借助`azure-mgmt-web` SDK,可通过初始化`WebSiteManagementClient`对象、调用`get_configuration`方法来查看`http_logging_enabled`的值,从而判断日志记录是否启用及存储方式(关闭、存储或文件系统)。示例代码详细展示了实现步骤,并附有执行结果与官方文档参考链接,帮助开发者快速定位和解决问题。
117 23
|
3月前
|
容器
【Azure Container App】在消耗性的Container App Environmnet中无法查看当时正在使用多少CPU多少实例数的替代方案
在 Azure Container Apps 中使用 Consumption 消耗型环境时,无法通过门户查看当前核心 (CPU) 和实例使用情况。这是因为消耗型工作负载配置文件的设计所致。若需查看使用状态,可使用 az cli 命令 `az containerapp env list-usages` 获取详细信息,包括 Current Cores 数量。文档还提供了参考资料链接以帮助用户深入了解相关命令用法。
80 17
|
3月前
|
网络协议
【Azure App Service】App Service 如何配置私网域名以及证书呢?
本文解答了关于 Azure App Service 如何配置私网域名及证书的问题。App Service 不支持私网域名,自定义域名需配置在公共 DNS 服务器上。文章引用官方文档详细说明了映射自定义 DNS 的步骤,并附带参考资料链接,帮助用户深入了解相关配置方法。
|
2月前
|
人工智能 JSON 小程序
【一步步开发AI运动APP】七、自定义姿态动作识别检测——之规则配置检测
本文介绍了如何通过【一步步开发AI运动APP】系列博文,利用自定义姿态识别检测技术开发高性能的AI运动应用。核心内容包括:1) 自定义姿态识别检测,满足人像入镜、动作开始/停止等需求;2) Pose-Calc引擎详解,支持角度匹配、逻辑运算等多种人体分析规则;3) 姿态检测规则编写与执行方法;4) 完整示例展示左右手平举姿态检测。通过这些技术,开发者可轻松实现定制化运动分析功能。

热门文章

最新文章