Нет данных в переменной - C#
Формулировка задачи:
var league = client.GetLeagues(29);
public async Task<List<League>> GetLeagues(int sportId)
{
return (await GetXmlAsync<LeaguesResponse>("leagues?sportid={0}", sportId)).Leagues;
}Решение задачи: «Нет данных в переменной»
textual
Листинг программы
protected async Task<T> GetXmlAsync<T>(string requestType, params object[] values)
where T : XmlResponse
{
var response = await _httpClient.GetAsync(string.Format(requestType, values)).ConfigureAwait(false);
var str = await _httpClient.GetStringAsync(string.Format(requestType, values));
response.EnsureSuccessStatusCode(); // throw if web request failed
var xmlFormatter = new XmlMediaTypeFormatter { UseXmlSerializer = true };
var apiResponse = await response.Content.ReadAsAsync<T>(new[] {xmlFormatter});
if (apiResponse.IsValid)
{
return apiResponse;
}
throw new Exception("Pinnacle Sports API error: " + apiResponse.Error.Message);
}