我正在测试 httpClient sendAsync 方法。同步调用它工作正常。但是,当我尝试执行异步 http 请求时,任务在我处理消息之前终止。任何机构遇到这个问题?
这个同步调用有效
HttpRequestMessage httprequest = new HttpRequestMessage(httpmethod, "http://www.google.ca");
var result = _httpClient.SendAsync(httprequest, HttpCompletionOption.ResponseContentRead, cancellationToken);
HttpResponseMessage response = result.Result;
但是异步调用不起作用。当我尝试解析响应时,线程死了。
HttpRequestMessage httprequest = new HttpRequestMessage(httpmethod, "http://www.google.ca");
var result = await _httpClient.SendAsync(httprequest, HttpCompletionOption.ResponseContentRead, cancellationToken);
HttpResponseMessage response = result;
任何帮助表示赞赏。