var uri = new Uri("https://www.dropbox.com/scl/fi/l2ltdldscgwr9ho1izx57/TestUpdate-pass.zip?rlkey=cn5adnh45sc3793j60gunn3x8&st=u8atpaop&dl=1");
var httpClientHandler = new HttpClientHandler
{
AllowAutoRedirect = true
};
var httpClient = new HttpClient(httpClientHandler);
httpClient.Timeout = TimeSpan.FromSeconds(60);
// Accept binary data
httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/octet-stream"));
HttpResponseMessage response = httpClient.GetAsync(uri).Result;
if (response.IsSuccessStatusCode)
{
byte[] zipFileData = response.Content.ReadAsByteArrayAsync().Result;
// Save the zip file to disk
File.WriteAllBytes("output.zip", zipFileData);
}
else
{
Console.WriteLine("{0}: {1} ({2})", uri, (int)response.StatusCode, response.ReasonPhrase);
}
I always got the errors: bad zip file, zip file corrupted when downloading the link with the HttpClient or any RestClient similar (Flurl, RestSharp, WebClient, etc.). The code is below. Please help....
Thank you.