c# - await HttpClient.SendAsync 没有响应
问题描述
我有一个返回输出的 curl 命令。Access Denied 对我来说很好,XML 输出是我目前感兴趣的。
curl -v -E C:\SEB\certificate.pfx --cert-type p12 -X GET https://test.api.bgw.baltics.sebgroup.com/v1/accounts/EE101010220279354221/current-transactions -H OrgId:22223338
我编写了一个代码片段,它应该与提供的 curl 命令执行相同的操作,但响应变量返回 null (当代码到达 line 时)
response = await httpClient.SendAsync(request);
程序退出,不再执行任何代码。
我究竟做错了什么?为什么我不能像 curl 命令一样获取响应的内容?
提前谢谢你的帮助
public async Task HttpRequestAppAsync()
{
var handler = new HttpClientHandler {ClientCertificateOptions = ClientCertificateOption.Manual};
handler.ClientCertificates.Add(new X509Certificate2("C:\\SEB\\certificate.pfx"));
using (var httpClient = new HttpClient(handler))
{
using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://test.api.bgw.baltics.sebgroup.com/v1/accounts/EE101010220279354221/current-transactions"))
{
request.Headers.TryAddWithoutValidation("OrgId", "22223338");
response = await httpClient.SendAsync(request);
}
}
}
解决方案
似乎已经想通了。死锁到位 我需要做的就是添加一个额外的方法 ConfigureAwait 并将其设置为 false
response = await httpClient.SendAsync(request).ConfigureAwait(false);
推荐阅读
- android - Android Firebase 获取数据库中的最后一个按键
- python - Python中的嵌套积分
- jena - 为什么 SHACL API 的 SHShape.hasTargetNode 对目标类返回 False?
- python - 在有序列表中选择 N 个变化点
- google-dfp - Prebid.js DFP 它们如何协同工作
- python - 无法从图表中打印每首歌曲的标题。获取属性错误?
- javascript - 是否可以使用“with”模板标签从 Django 模板中使用 JavaScript 生成的文本
- angular - 带有排序,分页和过滤页面问题的角度材料数据表
- sql - 如何在 SQL 中查询多条链接记录以返回一行
- ios - 在 iOS 上的 Swift 中使用 Realm DB 对应用程序大小的影响是什么