我正在使用WebClient下載文件。 但是,當它嘗試下載大於50mb大小的大文件時,會發生一些腥意,下載將在39kb之後完成,並且不會將其下載到最後。 任何人都知道可能是什麼問題?如果超過50MB,WebClient不能完全下載文件
using (webClient = new WebClient())
{
webClient.Proxy = null;
webClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)");
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
// The variable that will be holding the url address (making sure it starts with http://)
Uri URL = urlAddress.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ? new Uri(urlAddress) : new Uri("http://" + urlAddress);
// Start the stopwatch which we will be using to calculate the download speed
sw.Start();
try
{
// Start downloading the file
webClient.DownloadFileAsync(URL, _mainWindow.outputDirComboBox.SelectedItem.ToString() + "\\" + _compressedClientFileDownloadRelativePath, new List<object>
{
_compressedClientFileDownloadRelativePath,
_decompressedClientFileDownloadRelativePath,
_lastDownloadedFilePath,
_compressedSize,
_lastCompressedFilePartRelativePath,
_filePartsRelativePath,
urlAddress,
_clientFilePack,
_clientFile
});
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
DownloadFileCompleted只檢查錯誤,當它完成但沒有任何錯誤報告正在進行時。只有完成下載彷彿下載大小僅爲39KB
EDIT1: 雖然挖我會在這裏結束:Downloading Large Google Drive files with WebClient in C#
看起來像谷歌雲端硬盤,某種形式的確認鏈接,但即時通訊尚未能知道如何把所有的工作放在一起。
EDIT2: 我剛剛確認,該39KB的HTML頁面確認
在您完成使用之前,您正在處置Web客戶端,您預期會發生什麼? –
配置不會改變任何問題解決方案。 我試圖從Mega或谷歌驅動器下載文件,但沒有直接鏈接訪問API,這可能是問題嗎?因爲我只是試圖從speedtest下載:speedtest.tele2.net/100MB.zip,它的工作原理我不想爲我的公共應用程序提供谷歌驅動器或大型api證書,因爲它看起來像這些雲服務器限制爲每次50MB與webclient下載 – Supreme
檢查此https://stackoverflow.com/questions/2269607/how-to-programmatically-download-a-large-file-in-c-sharp –