C# Download file from webservice

前端 未结 1 1529
醉梦人生
醉梦人生 2021-01-06 18:45

I have a web service, like this example for downloading a zip file from the server. When i open the URL through web browsers,I can download the zip file correctly. The probl

1条回答
  •  有刺的猬
    2021-01-06 19:30

    You can try to use HttpClient instead. Usually, it is more convenient.

            var client = new HttpClient();
            var response = await client.GetAsync(@"http://localhost:9000/api/file/GetFile?filename=myPackage.zip");
    
            using (var stream = await response.Content.ReadAsStreamAsync())
            {
                var fileInfo = new FileInfo("myPackage.zip");
                using (var fileStream = fileInfo.OpenWrite())
                {
                    await stream.CopyToAsync(fileStream);
                }
            }
    

    0 讨论(0)
提交回复
热议问题