我正在尝试测量ASP.Net应用程序中的内容长度,如showen:
Stopwatch sto = new Stopwatch();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.google.com");
sto.Start();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Close();
sto.Stop();
int statusCode = (int)response.StatusCode; //save status code as int
if (response!= null) //reply.Status == System.Net.NetworkInformation.IPStatus.Success)
{
pinglbl.Text += "Latncy: " + sto.Elapsed.TotalSeconds + " s";
pinglbl.Text += "\r Status Code: " + statusCode;
pinglbl.Text += "\r Content Lenghth: " + response.ContentLength +"MB";
}
else
pinglbl.Text = "fail ping";
我总是得到这个输出:
结果历史:0.6525514 s状态代码:200内容长度: -1MB
是否存在持续获得-1作为内容长度的问题?