使用.Net Framework的System.Diagnostics库,我想模拟类似于我使用JMeter获得的东西。基本上我希望能够发送HTTPWebRequest,并且从响应中,我想尽可能准确地获得以下详细信息:
目前我有以下代码:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
request.CookieContainer = new CookieContainer();
request.Method = HTTPRequestType.GET.ToString();
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36";
Stopwatch watch = new Stopwatch();
watch.Start();
WebResponse webResponse = request.GetResponse();
watch.Stop();
HttpWebResponse httpResponse = (HttpWebResponse)webResponse;
Stream streamResponse = httpResponse.GetResponseStream();
使用此代码,我可以从手表的ElapsedTime属性中获取响应时间。我如何获得我想要的其他数据,并且我缺少我需要在我的请求中设置的任何重要属性,以使模拟尽可能准确(诸如cookie,缓存,用户代理等等) )?