获取HTML网页内容

        ///  
        ///  获取网址HTML 
        ///  
        /// 网址  
        ///   
        public static string GetHtml(string URL)
        {
            WebRequest wrt;
            wrt = WebRequest.Create(URL);
            wrt.Credentials = CredentialCache.DefaultCredentials;

            string opParam = "{\"appkey\":\"db54c95b\",\"pageNo\":\"1\",\"pageSize\":\"300\"}"; 

            wrt.Method = "POST";
            wrt.ContentType = "application/json";

// 下面是为了加入Json 参数
            byte[] bytes = Encoding.UTF8.GetBytes(opParam ); 

            Stream reqstream = wrt.GetRequestStream();
            reqstream.Write(bytes, 0, bytes.Length);

            WebResponse wrp;
            wrp = wrt.GetResponse();
            string reader = new StreamReader(wrp.GetResponseStream(), Encoding.GetEncoding("gb2312")).ReadToEnd();
            try
            {
                wrt.GetResponse().Close();
            }
            catch (WebException ex)
            {
                throw ex;
            }
            return reader;
        }

 

你可能感兴趣的:(MVC4,C#)