如何使用webclient获取电影大小,而无需下载? [英] How to use webclient to get a movie size, without download it?
本文介绍了如何使用webclient获取电影大小,而无需下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用WebClient获取电影大小,无需下载?
如果没有下载实际文件,我无法使用DownloadProgressChanged方法,实际下载过程链接。
我只想查询页面并仅提取数据,而没有实际内容。
谢谢。
我尝试了什么:
How to use WebClient to get a movie size, without download it?
Without downloading the actual file, I can not use the "DownloadProgressChanged" method, which is linked by the actual download process.
I only wish to interrogate the page and extract only the data, without the actual content.
Thanks.
What I have tried:
WebClient wc;
void Download4()
{
wc = new WebClient();
Uri uri = new Uri(url);
wc.DownloadFileAsync(uri, movieName);
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted);
}
void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
label1.Text = Website.SizeSuffix(e.BytesReceived) + "/" + Website.SizeSuffix(e.TotalBytesToReceive);
TotalBytesToReceive = TotalBytesToReceive + e.TotalBytesToReceive;
}
void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
label2.Text = TotalBytesToReceive.ToString();
}
推荐答案
当然你不需要下载整个文件,因为HTTP告诉你整个流将有多大。但要以这种方式解决问题,你不应该使用真正基本的System.Net.WebClient
。你必须使用HttpWebRequest
:
WebClient类(System.Net) [ ^ ],
HttpWebRequest Class(System.Net) [ ^ ]。br />
以下是我的建议:请下载我在过去的答案中提供的HttpDownloaded的完整代码:如何从互联网上下载文件 [ ^ ]。
此下载程序允许继续下载未完全下载的文件,这显然是基于获取网络流的完整大小从一开始就。你会看到如何做到这一点。这是一小段代码,只有一个文件;很容易阅读和理解。
另见我过去的答案:
如何从Asp.net 2.0中的服务器下载文件 [< a href =http://www.codeproject.com/Answers/212311/how-to-download-a-file-from-the-server-in-Asp-net#answer3target =_ blanktitle =新窗口> ^ ],
FTP:下载文件 [ ^ ],
如何从另一个站点获取数据 [ ^ ]。
-SA
Of course you don't need to download a whole file, because HTTP tells you how big the whole stream will be. But to solve the problem this way, you should not use really rudimentarySystem.Net.WebClient
. You have to useHttpWebRequest
instead:
WebClient Class (System.Net)[^],
HttpWebRequest Class (System.Net)[^].
Here is what I can suggest: please download the full code of my HttpDownloaded I provided in my past answer: how to download a file from internet[^].
This downloader allows to continue downloading of incompletely downloaded file, which apparently is based on getting the full size of a network stream from the very beginning. You will see how to do it. This is a very small piece of code, only one file; quite easy to read and understand.
See also my past answers:
how to download a file from the server in Asp.net 2.0[^],
FTP: Download Files[^],
How to get the data from another site[^].
—SA
这篇关于如何使用webclient获取电影大小,而无需下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文