专家,
我正在使用下面的代码来获取文档大小,但由于浏览器分析器显示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;
注意:Content-length返回-1。