无法使用C#获取网页大小

时间:2017-10-14 21:18:47

标签: c# .net httpwebrequest content-length http-content-length

enter image description here

专家,

我正在使用下面的代码来获取文档大小,但由于浏览器分析器显示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。

0 个答案:

没有答案