有一个WebAPI可以返回ZIP FOLDER。如果我在浏览器上单击或转到以下URL,则直接下载该文件:
WEB API网址:
http://54.186.6.13:81/api/DownloadAPI/DownloadTranslatedFile?projectid=17&fileid=
如何使用C#.net
下载ZIP文件/文件夹?
用于调用WEB API的我的C#.net代码:
using (var client = new HttpClient())
{
using (var responseT = client.GetAsync(XMLPath).GetAwaiter().GetResult())
{
if (responseT.IsSuccessStatusCode)
{
// HOW I DOWNLOAD THE ZIP FILE, WHICH IS RETURNED BY
THE ABOVE WEB API
}
}
}
答案 0 :(得分:1)
你应该尝试以下方法:
FileStream file = await (FileStream)responseT.Content.ReadAsStreamAsync();
var copyToFile = File.Create("C:\\path\\to\\where\\you\\want\\the\\file.zip");
await file.CopyToAsync(copyToFile);