
C# Neden bu şekilde program çalışıyorken hata veriyor?
4
●130
- 27-12-2021, 01:05:08Aramızdan Ayrılanlar - Vefatpublic static class HttpClientExtensionsRipRi adlı üyeden alıntı: mesajı görüntüle
{
public static async Task DownloadAsync(this HttpClient client, string requestUri, Stream destination, IProgress<float>? progress = null, CancellationToken cancellationToken = default)
{
// Get the http headers first to examine the content length
var response = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead);
var contentLength = response.Content.Headers.ContentLength;
await using var download = await response.Content.ReadAsStreamAsync();
// Ignore progress reporting when no progress reporter was
// passed or when the content length is unknown
if (progress == null || !contentLength.HasValue)
{
await download.CopyToAsync(destination);
return;
}
// Convert absolute progress (bytes downloaded) into relative progress (0% - 100%)
var relativeProgress = new Progress<long>(totalBytes => progress.Report((float)totalBytes / contentLength.Value));
// Use extension method to report progress while downloading
await download.CopyToAsync(destination, 81920, relativeProgress, cancellationToken);
progress.Report(1);
}
}
} - 27-12-2021, 01:15:03var response = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead);
zaten get isteği atıyorsunuz requestUri ye browser üzerinden istek atın açılıyor mu kontrol edin. Açılıyorsa request header a User-Agent ekleyip deneyin ve localde 5001 üzerinden çalıştırıp local sertifika aktif etmeyi deneyin.
{'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.3'}
Burada yazanlarıda kontrol edebilirsiniz: https://stackoverflow.com/questions/...-visual-studio