How do I download zip file in C#?

后端 未结 4 702
梦如初夏
梦如初夏 2020-12-17 10:56

I use HTTP GET that downloads a zip file in a browser, something like https://example.com/up/DBID/a/rRID/eFID/vVID (not the exact url)

Now, when I try to do the sam

4条回答
  •  佛祖请我去吃肉
    2020-12-17 11:03

    You can also use System.Net.Http.HttpClient

    using (HttpClient client = new HttpClient())
    {
            using (HttpResponseMessage response = await client.GetAsync(downloadURL))
            {
                 using(var stream = await response.Content.ReadAsStreamAsync())
                 {
                      using(Stream zip = FileManager.OpenWrite(ZIP_PATH))
                      {
                           stream.CopyTo(zip);
                      }
                 }
            }
    }
    

提交回复
热议问题