private async Task <DownloadResult> DownloadUrl(DownloadInstruction instruction) { using (HttpClient client = new HttpClient()) { //prepare request headers if (instruction.ContainRequestHeader) { ModifyRequestHeader(client.DefaultRequestHeaders, instruction.RequestHeader); } //Now that we are set and ready, go and do the download call using (HttpResponseMessage response = await client.GetAsync(instruction.Uri)) { using (HttpContent content = response.Content) { Stream result = await content.ReadAsStreamAsync(); MemoryStream mem = new MemoryStream(); result.CopyTo(mem); Dictionary <string, string> headers = content.Headers.ToDictionary( x => CultureInfo.CurrentCulture.TextInfo.ToTitleCase(x.Key), x => string.Join(",", x.Value)); return(new DownloadResult(instruction.Uri, mem, headers)); } } } }
private async Task<DownloadResult> DownloadUrl(DownloadInstruction instruction) { using (HttpClient client = new HttpClient()) { //prepare request headers if (instruction.ContainRequestHeader) { ModifyRequestHeader(client.DefaultRequestHeaders, instruction.RequestHeader); } //Now that we are set and ready, go and do the download call using (HttpResponseMessage response = await client.GetAsync(instruction.Uri)) { using (HttpContent content = response.Content) { Stream result = await content.ReadAsStreamAsync(); MemoryStream mem = new MemoryStream(); result.CopyTo(mem); Dictionary<string, string> headers = content.Headers.ToDictionary( x => CultureInfo.CurrentCulture.TextInfo.ToTitleCase(x.Key), x => string.Join(",", x.Value)); return new DownloadResult(instruction.Uri, mem, headers); } } } }