【发布时间】:2016-02-09 23:33:14
【问题描述】:
我正在使用 httpclient 进行 api 调用,但是当使用 async 时,该类只能为 void,因此我试图弄清楚如何将值返回到我的 Controller 并返回到视图。
public async void GetResult(){
using(var httpClient = new HttpClient()){
var httpResponse = await httpClient.GetAsync(requestMessage);
var responseContent = await httpResponse.Content.ReadAsStringAsync();
}
}
现在我有了 responseContent(value),我想将它返回给我的控制器,但每次我尝试删除 void 时,它都会说 async 仅适用于 void。
【问题讨论】:
标签: c# asp.net asp.net-web-api