C# UWP HttpClient、HTTP/2和客户端证书的重复故障

C# UWP HttpClient、HTTP/2和客户端证书的重复故障,c#,networking,apple-push-notifications,win-universal-app,desktop-application,C#,Networking,Apple Push Notifications,Win Universal App,Desktop Application,问题 我们已经构建了一个Windows10应用程序,可以向iOS设备发送推送通知。在进行负载测试时,我们发现UWP的HttpClient类有一个相当严重的bug,似乎无法诊断 我们的UWP应用程序向苹果的APN服务器发送推送通知。我们可以发送HTTP/2 TLS请求,只要每隔几秒钟发送一条消息,一切都正常 但如果我们在HTTP/2请求之间等待一分钟左右,HttpClient将完全崩溃,返回一个COMException,错误代码为0x80072efd,COM错误文本为“无法建立与服务器的连接” 我

问题

我们已经构建了一个Windows10应用程序,可以向iOS设备发送推送通知。在进行负载测试时,我们发现UWP的HttpClient类有一个相当严重的bug,似乎无法诊断

我们的UWP应用程序向苹果的APN服务器发送推送通知。我们可以发送HTTP/2 TLS请求,只要每隔几秒钟发送一条消息,一切都正常

但如果我们在HTTP/2请求之间等待一分钟左右,HttpClient将完全崩溃,返回一个COMException,错误代码为0x80072efd,COM错误文本为“无法建立与服务器的连接”

我们使用相同的负载和适当的客户端证书,针对我们自己的基于web的HTTP/2服务器(Nginx后面的ASP.NET核心HTTPS)测试了此场景。这里一切正常——因此这个问题似乎与HttpClient与Apple APN客户端证书或Apple的HTTP/2前端的互操作性无关

尝试诊断

/* code called during app startup */
Certificate clientCertificate = [apns certificate omitted for security];
string deviceToken = "[omitted for security]";
string appBundleId = "[omitted for security]";
//
Windows.Web.Http.Filters.HttpBaseProtocolFilter filter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
filter.ClientCertificate = clientCertificate;
var client = new Windows.Web.Http.HttpClient(filter);


/* code called every time a push notification needs to be sent */
string messageUuid = Guid.NewGuid().ToString("D");
//
var request = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Post, new Uri("https://api.development.push.apple.com:443/3/device/" + deviceToken));
//
request.Headers.Add("apns-id", messageUuid);
request.Headers.Add("apns-expiration", "0");
request.Headers.Add("apns-priority", "10");
request.Headers.Add("apns-topic", appBundleId);
// sample notification content for testing purposes only 
request.Content = new Windows.Web.Http.HttpStringContent("{ \"aps\" : { \"alert\" : \" -- test message " + messageUuid + " -- \" } }");
//
try
{
    // this next line of code works fine if called a few seconds after the last message--but throws a COMException if a minute has passed
    var response = await client.SendRequestAsync(request);
}
catch (Exception ex)
{
    System.Diagnostics.Debug.Write(ex.Message);
}
为了诊断该问题,我们安装了mitmproxy(支持HTTP/2和客户端证书),但mitmproxy使用的HTTP/2实现运行良好,没有出现与UWP的HttpClient类相同的问题,因此我们无法在那里调试该问题

我们也尝试过使用Fiddler,但是Fiddler(以及微软的消息分析器使用的Fiddler内核)只支持早期的HTTP/2并破坏了HTTP/2流

当然,我们使用SSLSPLIT和类似的解决方案查看了诊断,但没有找到任何能够处理HTTP/2和客户端证书的诊断工具

代码,供参考

/* code called during app startup */
Certificate clientCertificate = [apns certificate omitted for security];
string deviceToken = "[omitted for security]";
string appBundleId = "[omitted for security]";
//
Windows.Web.Http.Filters.HttpBaseProtocolFilter filter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
filter.ClientCertificate = clientCertificate;
var client = new Windows.Web.Http.HttpClient(filter);


/* code called every time a push notification needs to be sent */
string messageUuid = Guid.NewGuid().ToString("D");
//
var request = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Post, new Uri("https://api.development.push.apple.com:443/3/device/" + deviceToken));
//
request.Headers.Add("apns-id", messageUuid);
request.Headers.Add("apns-expiration", "0");
request.Headers.Add("apns-priority", "10");
request.Headers.Add("apns-topic", appBundleId);
// sample notification content for testing purposes only 
request.Content = new Windows.Web.Http.HttpStringContent("{ \"aps\" : { \"alert\" : \" -- test message " + messageUuid + " -- \" } }");
//
try
{
    // this next line of code works fine if called a few seconds after the last message--but throws a COMException if a minute has passed
    var response = await client.SendRequestAsync(request);
}
catch (Exception ex)
{
    System.Diagnostics.Debug.Write(ex.Message);
}
问题

  • 如果有任何选项可用于诊断Windows 10上的WinInet/HttpClient故障,该怎么办?混合使用HTTP/2、TLS和客户端证书

  • 苹果选定的HTTP/2实现有什么特别之处吗?众所周知,它会导致UWP的HttpClient出现问题,并且有一个已知的解决方法