Exemplo n.º 1
0
        private HttpWebResponse FetchResponseWithProxy(string url, HttpMethod method, string referer, string postData)
        {
            HttpWebResponse httpWebResponse = null;

            try
            {
                if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
                {
                    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                    httpWebRequest.Proxy       = new WebProxy("Insert Proxy IP Here", 1111);
                    httpWebRequest.UserAgent   = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0";
                    httpWebRequest.Accept      = this.accept;
                    httpWebRequest.KeepAlive   = this.keepAlive;
                    httpWebRequest.ContentType = this.contentType;
                    if (!string.IsNullOrEmpty(referer))
                    {
                        httpWebRequest.Referer = referer;
                    }
                    object cookielocker;
                    Monitor.Enter(cookielocker = this._cookielocker);
                    try
                    {
                        httpWebRequest.CookieContainer = this.cookieContainer;
                    }
                    finally
                    {
                        Monitor.Exit(cookielocker);
                    }
                    httpWebRequest.Method = method.ToString().ToUpper();
                    if (method == HttpMethod.Post && !string.IsNullOrEmpty(postData))
                    {
                        byte[] bytes = this.postDataEncoding.GetBytes(postData);
                        httpWebRequest.ContentLength = (long)bytes.Length;
                        Stream requestStream = httpWebRequest.GetRequestStream();
                        requestStream.Write(bytes, 0, bytes.Length);
                        requestStream.Close();
                    }
                    httpWebResponse         = (HttpWebResponse)httpWebRequest.GetResponse();
                    httpWebResponse.Cookies = httpWebRequest.CookieContainer.GetCookies(httpWebRequest.RequestUri);
                    object cookielocker2;
                    Monitor.Enter(cookielocker2 = this._cookielocker);
                    try
                    {
                        this.cookies.Add(httpWebResponse.Cookies);
                        this.cookieContainer.Add(this.cookies);
                    }
                    finally
                    {
                        Monitor.Exit(cookielocker2);
                    }
                }
            }
            catch (Exception ex)
            {
                this.CloseResponse(httpWebResponse);
                httpWebResponse = null;
                EngineLogger.Log(ex, LogMode.Normal, StaticLog.Main);
            }
            return(httpWebResponse);
        }
Exemplo n.º 2
0
        public Image FetchImageWithProxy(string url, HttpMethod method, string referer, string postData)
        {
            Image result = null;

            try
            {
                using (HttpWebResponse httpWebResponse = this.FetchResponseWithProxy(url, method, referer, postData))
                {
                    if (httpWebResponse != null)
                    {
                        using (Stream responseStream = httpWebResponse.GetResponseStream())
                        {
                            using (StreamReader streamReader = new StreamReader(responseStream, this.responseEncoding, true))
                            {
                                result = Image.FromStream(streamReader.BaseStream);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                EngineLogger.Log(ex, LogMode.Normal, StaticLog.Main);
                string message = this.Fetch(url, method, referer, postData);
                EngineLogger.Log("FK==>>>", message, LogMode.Normal, StaticLog.Main);
            }
            return(result);
        }
Exemplo n.º 3
0
        public string FetchWithProxy(string url, HttpMethod method, string referer, string postData)
        {
            string result = string.Empty;

            try
            {
                using (HttpWebResponse httpWebResponse = this.FetchResponseWithProxy(url, method, referer, postData))
                {
                    if (httpWebResponse != null)
                    {
                        using (Stream responseStream = httpWebResponse.GetResponseStream())
                        {
                            using (StreamReader streamReader = new StreamReader(responseStream, this.responseEncoding, true))
                            {
                                result = streamReader.ReadToEnd();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                EngineLogger.Log(ex, LogMode.Normal, StaticLog.Main);
            }
            return(result);
        }
Exemplo n.º 4
0
        public string FetchResponseUriWithProxy(string url, HttpMethod method, string referer, string postData)
        {
            string result = string.Empty;

            try
            {
                using (HttpWebResponse httpWebResponse = this.FetchResponseWithProxy(url, method, referer, postData))
                {
                    if (httpWebResponse != null)
                    {
                        result = httpWebResponse.ResponseUri.AbsoluteUri;
                    }
                }
            }
            catch (Exception ex)
            {
                EngineLogger.Log(ex, LogMode.Normal, StaticLog.Main);
            }
            return(result);
        }
Exemplo n.º 5
0
        private HttpWebResponse FetchResponse(string url, HttpMethod method, string referer, string postData)
        {
            HttpWebResponse httpWebResponse = null;

            try
            {
                if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
                {
                    //WebRequest.DefaultWebProxy = null;
                    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                    httpWebRequest.UserAgent   = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0";
                    httpWebRequest.Accept      = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                    httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                    httpWebRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
                    httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
                    httpWebRequest.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us,en;q=0.5");
                    httpWebRequest.Headers.Add(HttpRequestHeader.KeepAlive, "true");
                    if (!string.IsNullOrEmpty(referer))
                    {
                        httpWebRequest.Referer = referer;
                    }
                    object cookielocker;
                    Monitor.Enter(cookielocker = this._cookielocker);
                    try
                    {
                        httpWebRequest.CookieContainer = this.cookieContainer;
                    }
                    finally
                    {
                        Monitor.Exit(cookielocker);
                    }
                    httpWebRequest.Method = method.ToString().ToUpper();
                    if (method == HttpMethod.Post && !string.IsNullOrEmpty(postData))
                    {
                        byte[] bytes = this.postDataEncoding.GetBytes(postData);
                        httpWebRequest.ContentLength = (long)bytes.Length;
                        Stream requestStream = httpWebRequest.GetRequestStream();
                        requestStream.Write(bytes, 0, bytes.Length);
                        requestStream.Close();
                    }
                    httpWebResponse         = (HttpWebResponse)httpWebRequest.GetResponse();
                    httpWebResponse.Cookies = httpWebRequest.CookieContainer.GetCookies(httpWebRequest.RequestUri);
                    object cookielocker2;
                    Monitor.Enter(cookielocker2 = this._cookielocker);
                    try
                    {
                        this.cookies.Add(httpWebResponse.Cookies);
                        this.cookieContainer.Add(this.cookies);
                    }
                    finally
                    {
                        Monitor.Exit(cookielocker2);
                    }
                }
            }
            catch (Exception ex)
            {
                this.CloseResponse(httpWebResponse);
                httpWebResponse = null;
                EngineLogger.Log(ex, LogMode.Normal, StaticLog.Main);
            }
            return(httpWebResponse);
        }
Exemplo n.º 6
0
        public static void Log(Exception ex, LogMode mode, StaticLog type)
        {
            string message = string.Format("{0}\r\n{1}", ex.Message, ex.StackTrace);

            EngineLogger.Log(ex.TargetSite.Name, message, mode, type);
        }