ConfigureAwait出错(false)

时间:2016-03-18 11:19:37

标签: c# json api

我正在尝试从API中检索一些数据,以下是我的一段代码,它在验证并分配完成的URL后发出请求。

public async Task<T> GetAPIData<T>(string url)
{
    using (var client = HttpClientSetup())
    {
        var response = await client.GetAsync(url).ConfigureAwait(false);

         var JsonResponse = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
         return JsonConvert.DeserializeObject<T>(JsonResponse);
    }
}

private HttpClient HttpClientSetup()
{
    var client = new HttpClient { BaseAddress = new Uri(apiBaseUrl) };
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    client.DefaultRequestHeaders.Authorization = authenticationHeader;
    return client;
}

我在ConfigureAwait(false);一行收到错误  如

  

&#34; HTTPResponseMessage不包含ConfigureAwait的定义&#34;

。任何人都可以帮我解决可能出现的问题吗?

0 个答案:

没有答案