netcore GetAsync 下载文件流
[HttpGet] public async Task<IActionResult> Get4() { var client = _httpClientFactory.CreateClient(); var resp = await client.GetAsync("http://localhost:99/api/httpfile/GetFile"); var con_dis = resp.Content.Headers.Where(o => o.Key == "Content-Disposition").Select(m => m.Value).FirstOrDefault().FirstOrDefault(); Regex regex = new Regex("filename=(.+);"); var filename = regex.Match(con_dis).Groups[1].Value; var ext = filename.Split('.').Reverse().First(); new FileExtensionContentTypeProvider().Mappings.TryGetValue("." + ext, out var contenttype); var buffer = await resp.Content.ReadAsByteArrayAsync(); return File(buffer, contenttype, filename); }
可以直接下载文件