我正在尝试从我们的API实例中获取数据。我拥有的代码几乎复制了MS网站,并在SO上找到了柚木。我正在使用的代码是这样的:
string peopleEndpoint = $"{apiConf.ApiEndpoint}/{apiConf.dbspec}/_table/mdm.PEOPLE_SV";
string json = null;
try
{
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiConf.ApiKey);
HttpResponseMessage response = await httpClient.GetAsync(peopleEndpoint);
json = await response.Content.ReadAsStringAsync();
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
throw;
}
配置值很好...我可以复制它们并将其粘贴到cURL命令中并获取数据。与标题相同。
现在,当我调试时,执行以下行将停止执行:
HttpResponseMessage response = await httpClient.GetAsync(peopleEndpoint);
然后,在输出窗口中,我看到的是:
The program '[10172] dotnet.exe' has exited with code 0 (0x0).
The program '[10172] dotnet.exe: Program Trace' has exited with code 0 (0x0).
我如何找出导致此故障的原因?
该框架标记为:
<TargetFramework>netcoreapp2.1</TargetFramework>
答案 0 :(得分:1)
代码是一直到顶部都是异步的,还是有一个非异步方法在某个地方调用该代码,而该方法可能要等到完成为止。这就是我的气味。