我向网站发出http请求,但我希望在网站加载后5秒获取网页的源代码。
string html = string.Empty;
string url = @"https://***.com";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36";
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(new Cookie("", "****") { Domain = "***" });
request.AutomaticDecompression = DecompressionMethods.GZip;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
html = reader.ReadToEnd();
ViewBag.Html = html;
return View();