我只是想知道这是否可行 - 我知道如何下载文件,但如何只下载文件的前 100KB?
最佳答案
试试这个:
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;
}
从 here 窃取。
关于c# - 是否可以在 C# 中仅下载文件的一部分(例如,前 100KB)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3443238/