在获得响应之前,如何让http请求等待5秒?

时间:2017-04-21 12:55:05

标签: c# asp.net http

我向网站发出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();

0 个答案:

没有答案