Ejemplo n.º 1
0
        private HttpWebRequest createRequest(DownloadParamers paramers)
        {
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(paramers.Url);

            req.Method          = paramers.Method;
            req.KeepAlive       = paramers.KeepAlive;
            req.Timeout         = paramers.Timeout;
            req.CookieContainer = paramers.Cookie;
            req.Proxy           = paramers.Proxy;
            req.UserAgent       = paramers.UserAgent;
            req.Accept          = paramers.Accept;
            req.Referer         = paramers.Referer;

            return(req);
        }
Ejemplo n.º 2
0
        public string DownLoad(DownloadParamers paramers, Encoding encoding)
        {
            try
            {
                DownloadResult result = new DownloadResult();

                var response = (HttpWebResponse)createRequest(paramers).GetResponse();
                result.Stream      = response.GetResponseStream();
                result.Cookie      = response.Cookies;
                result.ContentType = response.ContentType;

                var reader = new StreamReader(result.Stream, encoding);

                return(reader.ReadToEnd());
            }
            catch (Exception ex)
            {
                return(null);
            }
        }