C#HttpWebRequest, HttpWebResponse 아날로그 브라우저를 사용하여 웹 내용을 캡처하는 방법

3081 단어 response
public string GetHtml(string url, Encoding ed)
        {
            string Html = string.Empty;// webRequst
            HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url);

            Request.KeepAlive = true;
            Request.ProtocolVersion = HttpVersion.Version11;
            Request.Method = "GET";
            Request.Accept = "*/* ";
            Request.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5";
            Request.Referer = url;

            HttpWebResponse htmlResponse = (HttpWebResponse)Request.GetResponse();
            // Internet 
            Stream htmlStream = htmlResponse.GetResponseStream();
            // 
            StreamReader weatherStreamReader = new StreamReader(htmlStream, ed);
            // 
            Html = weatherStreamReader.ReadToEnd();
            weatherStreamReader.Close();
            htmlStream.Close();
            htmlResponse.Close();
            // html 
            return Html;
        }

        public string GetHtml(string url)
        {
            return GetHtml(url, Encoding.UTF8);
        }

좋은 웹페이지 즐겨찾기