Вот мой код:
Код: Выделить всё
[HttpGet]
[Route("customerslist")]
public async Task getData()
{
string url1 = @"https://jsonplaceholder.typicode.com/photos";
string url2 = @"https://jsonplaceholder.typicode.com/comments";
string url3 = @"https://jsonplaceholder.typicode.com/todos";
Task firstTask = myHttpCall(url1);
Task secondTask = myHttpCall(url2);
Task thirdTask = myHttpCall(url3);
await Task.WhenAll(firstTask, secondTask, thirdTask);
var result = firstTask.Result + secondTask.Result + thirdTask.Result;
return Ok(result);
}
private async Task myHttpCall(string path)
{
string html = string.Empty;
string url = path;
// Simple http call to another URL to receive JSON lists.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.AutomaticDecompression = DecompressionMethods.GZip;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
html = reader.ReadToEnd();
}
return html;
}
Подробнее здесь: https://stackoverflow.com/questions/456 ... sync-await
Мобильная версия