c# - HttpClient HTTP/2 从 Azure Function 调用 APN
问题描述
我正在使用 HttpClient 将 Apple 推送通知发送到 APN HTTP/2 服务器。我已经设法通过使用System.Net.Http.WinHttpHandler
nuget 包让它工作:
var http = new HttpClient(new WinHttpHandler());
var request = new HttpRequestMessage(HttpMethod.Post, new Uri(url))
{
Version = new Version(2, 0),
Content = new StringContent(json)
};
// Set headers... Send... Read response... HTTP 200 OK
这在 Windows 上运行良好。问题是,其他任何地方都不支持 WinHttpHandler。例如,我无法从 Azure Functions 运行此代码。我的问题是 - 是否有任何使用 .NET Core 2.1 发送 HTTP/2 请求的跨平台方式,或者 Azure Functions 2.0 是否有任何变通方法使其正常工作?
解决方案
我在 Azure Functions 2.0 上使用 WinHttpHandler 时遇到问题。我已经设法使用此处的解决方法解决了它。基本上,我将 .NET Standard 2.0 System.Net.Http.WinHttpHandler.dll 程序集放到函数项目的根目录中,并添加了以下内容:
<ItemGroup>
<None Update="System.Net.Http.WinHttpHandler.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="CopySPSM" BeforeTargets="Build">
<Copy SourceFiles="System.Net.Http.WinHttpHandler.dll" DestinationFolder="$(OutputPath)\bin" />
</Target>
有了它并设置了 WEBSITE_LOAD_USER_PROFILE = 1 来CngKey.Import
为 APN 签名 JWT 令牌,它就开始工作了。
推荐阅读
- jquery - 单击父选项卡时如何默认打开子选项卡
- c# - 带有布尔值的 if 语句进入 switch 方法
- ios - 在 iOS 中更改用户密码时,MSGraphSDK 用户详细信息 API 回调没有响应
- java - 如何加密/解密 blueprint.xml 中的密码?
- excel - 在循环中根据单元格值隐藏行
- css - Chrome 正在破坏布局,我该如何解决?
- excel - 文件打开时如何阻止单元格?
- file - 使用 perl 将文本文件转换为二进制文件的问题
- java - Rest API 获取 POST 请求而不是 GET
- php - 在编辑订单页面上的自定义 Woocommerce 订单号下添加 order_id