WebRequest 转存静态页

 HttpWebRequest request = null;

        HttpWebResponse response = null;

        StreamReader reader = null;

        try

        {

            request = (HttpWebRequest)WebRequest.Create(url);            

            request.Timeout = 20000;

            request.AllowAutoRedirect = false;

            response = (HttpWebResponse)request.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK && response.ContentLength < 1024 * 1024)

            {

                reader = new StreamReader(response.GetResponseStream(), encoding);

                string html = reader.ReadToEnd();

                return clearHTML(html);

            }

        }

        catch { }

        finally

        {

            if (response != null)

            {

                response.Close();

                response = null;

            }

            if (reader != null)

                reader.Close();

            if (request != null)

                request = null;

        }

  

你可能感兴趣的:(request)