【发布时间】:2017-03-05 15:41:48
【问题描述】:
大家好,我关注this guide
static async Task<Product> GetProductAsync(string path)
{
Product product = null;
HttpResponseMessage response = await client.GetAsync(path);
if (response.IsSuccessStatusCode)
{
product = await response.Content.ReadAsAsync<Product>();
}
return product;
}
我在我的代码中使用了这个例子,我想知道有没有什么方法可以在没有async/await 的情况下使用HttpClient,我怎样才能只得到响应字符串?
提前谢谢你
【问题讨论】:
-
为什么不用
WebClient.DownloadString而不是以不适合使用的方式扭曲HttpClient?
标签: c# asp.net asp.net-mvc webclient