我只是好奇这是否可能——我知道如何下载文件,但我怎样才能只下载文件的前 100KB?
问问题
330 次
1 回答
8
试试这个:
string GetWebPageContent(string url)
{
string result = string.Empty;
HttpWebRequest request;
const int bytesToGet = 1000;
request = WebRequest.Create(url) as HttpWebRequest;
//get first 1000 bytes
request.AddRange(0, bytesToGet - 1);
// the following code is alternative, you may implement the function after your needs
using (WebResponse response = request.GetResponse())
{
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
result = sr.ReadToEnd();
}
}
return result;
}
从这里偷来的。
于 2010-08-09T19:01:53.760 回答