关于网友提出的“下载网页,如何提高下载速度?”问题疑问,本网通过在网上对“下载网页,如何提高下载速度?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题:下载网页,如何提高下载速度?
描述:
private void SavePageFile(string title, byte[] vPageContent,string url,string web)
{
string strFile = "";
string newfile = "";
if (title=="")
{
int iStart = url.IndexOf(".");
int iend = url.IndexOf(".", iStart + 1);
if (iend>iStart )
newfile = url.Substring(iStart, iend - iStart);
if (newfile=="")
{
iStart = web.IndexOf(".")+1;
iend = web.IndexOf(".", iStart );
newfile = web.Substring(iStart, iend - iStart);
}
}
else
newfile=title;
strFile = string.Format("{0}{1}.html", newfile, DateTime.Now.Ticks.ToString());
string dates = DateTime.Now.Year.ToString();
dates =dates + DateTime.Now.Month.ToString("00");
dates =dates + DateTime.Now.Day.ToString("00");
if (!Directory.Exists("C:\\webfile\\" + dates))
{
Directory.CreateDirectory("C:\\webfile\\" + dates );
}
strFile = @"c:\webfile\" + dates + @"\" + strFile;
File.WriteAllBytes(strFile, vPageContent);
}
以上是我写的下载页面的方法,可是这个下载速度很慢,有没办法修改代码提高下载速度?因为我有1万多个页面下载,这个方法下载得太慢了
解决方案1: WebClient client = new WebClient();
byte[] bytRecv = client.DownloadData(web);
就这两句话有用,其他的都没用
你用这种下载方式,那么1是取决于服务器的响应速度,2是取决于服务器提供的下载方法
你用多线程分块下载肯定比你用单线程顺序下载要快的多
以上介绍了“下载网页,如何提高下载速度?”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/1129023.html