bezzad / Downloader

Fast, cross-platform and reliable multipart downloader with asynchronous progress events for .NET applications.
MIT License
1.25k stars 193 forks source link

how to download stream or api link? #151

Closed ghost1372 closed 8 months ago

ghost1372 commented 9 months ago

Hi @bezzad tnx for Great library.

I have an api that requires 2 input for the header, after that if everything goes well the result is a stream that I can save with the following code

HttpClient client = new HttpClient();

client.DefaultRequestHeaders.Add("Authorization", "Bearer");
client.DefaultRequestHeaders.Add("Authorization2", "00");
string url = "https://api.my.com/api/v1/myapi";
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
    Stream stream = await response.Content.ReadAsStreamAsync();
    string filename = "file.zip";
    using FileStream fileStream = File.Create(filename);
    await stream.CopyToAsync(fileStream);
    fileStream.Close();
}

is there any way i can download this file with Downloader library?