专家们,
我正在使用下面的代码来获取文档大小,但由于浏览器分析器显示 200 KB 大小但我得到 50 KB,因此长度不正确。有人可以帮忙吗?
string URL = "https://www.google.com/";
Uri uri = new Uri(URL);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
var response = (WebResponse)request.GetResponse();
var resultStream = new MemoryStream();
using (var respStream = response.GetResponseStream())
{
respStream.CopyTo(resultStream);
}
byte[] data = resultStream.GetBuffer();
int length1 = data.Length;
decimal length = data.LongLength / 1024;
注意:内容长度返回 -1。