예제 #1
0
        private WebRequest CreateProperRequestType(string url, IProxyDetails proxyDetails)
        {
            WebRequest result = null;

            if (proxyDetails != null)
            {
                if (proxyDetails.ProxyType == ProxyType.Proxy)
                {
                    result       = (HttpWebRequest)WebRequest.Create(url);
                    result.Proxy = new WebProxy(proxyDetails.FullProxyAddress);
                    ((HttpWebRequest)result).UserAgent = _userAgent;
                }
                else if (proxyDetails.ProxyType == ProxyType.Socks)
                {
                    result       = SocksHttpWebRequest.Create(url);
                    result.Proxy = new WebProxy(proxyDetails.FullProxyAddress);
                    //TODO: implement user and password
                }
                else if (proxyDetails.ProxyType == ProxyType.None)
                {
                    result = (HttpWebRequest)WebRequest.Create(url);
                    ((HttpWebRequest)result).UserAgent = _userAgent;
                }
            }
            else
            {
                result = (HttpWebRequest)WebRequest.Create(url);
                ((HttpWebRequest)result).UserAgent = _userAgent;
            }


            return(result);
        }
예제 #2
0
        protected string GetContentUsingHttp(string url)
        {
            string ret = string.Empty;

            WebRequest request = IsSocksProxy ? SocksHttpWebRequest.Create(url) : WebRequest.Create(url);

            if (WebProxy != null)
            {
                request.Proxy = WebProxy;
            }

            if (Credential != null)
            {
                request.PreAuthenticate = true;
                request.Credentials     = Credential;
            }

            if (request is HttpWebRequest)
            {
                var r = request as HttpWebRequest;
                r.UserAgent        = UserAgent;
                r.ReadWriteTimeout = TimeoutMs * 6;
                r.Accept           = requestAccept;
                r.Referer          = RefererUrl;
                r.Timeout          = TimeoutMs;
            }
            else if (request is SocksHttpWebRequest)
            {
                var r = request as SocksHttpWebRequest;

                if (!string.IsNullOrEmpty(UserAgent))
                {
                    r.Headers.Add("User-Agent", UserAgent);
                }

                if (!string.IsNullOrEmpty(requestAccept))
                {
                    r.Headers.Add("Accept", requestAccept);
                }

                if (!string.IsNullOrEmpty(RefererUrl))
                {
                    r.Headers.Add("Referer", RefererUrl);
                }
            }
            using (var response = request.GetResponse())
            {
                using (Stream responseStream = response.GetResponseStream())
                {
                    using (StreamReader read = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        ret = read.ReadToEnd();
                    }
                }
                response.Close();
            }

            return(ret);
        }
        public static SocksHttpWebRequest getWebRequest(string url)
        {
            SocksHttpWebRequest wc = (SocksHttpWebRequest)SocksHttpWebRequest.Create(url);

            wc.Proxy = new System.Net.WebProxy("127.0.0.1:9050");

            return(wc);
        }
예제 #4
0
        protected override WebRequest GetWebRequest(Uri address)
        {
            var request = SocksHttpWebRequest.Create(address, this.Cookies, this.ProxyType);

            request.Headers = this.Headers;
            request.Proxy   = this.Proxy;
            return(request);
        }
예제 #5
0
        protected override WebRequest GetWebRequest(Uri address)
        {
            WebRequest request = null;

            if (Proxy.ProxyType != ProxyTypeEnum.Socks)
            {
                request = base.GetWebRequest(address);
            }
            else
            {
                request = SocksHttpWebRequest.Create(address);
                var br = base.GetWebRequest(address);
                request.Method        = br.Method;
                request.ContentLength = br.ContentLength;
                request.ContentType   = br.ContentType;
            }


            request.Headers.Add("Cookie", Cookies.GetCookieHeader(address));
            request.Headers.Add("Accept-Language", AcceptLanguage);
            request.Headers.Add("Accept-Encoding", AcceptEncoding);
            if (CustomHeaders != null)
            {
                foreach (string key in CustomHeaders.AllKeys)
                {
                    request.Headers.Add(key, CustomHeaders[key]);
                }
            }


            if (Proxy.ProxyType != ProxyTypeEnum.Socks)
            {
                var httpRequest = (request as HttpWebRequest);
                httpRequest.UserAgent = UserAgent;
                httpRequest.Accept    = Accept;
                httpRequest.Referer   = Referer;
                httpRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
                httpRequest.AllowAutoRedirect      = AllowAutoRedirect;
                // TO IMPLEMANT IF REQUIRED httpRequest.RefuseOtherDomainRedirect = RefuseOtherDomainRedirect;
            }
            else if (Proxy.ProxyType == ProxyTypeEnum.Socks)
            {
                var socksRequest = (request as SocksHttpWebRequest);
                socksRequest.UserAgent                           = UserAgent;
                socksRequest.Accept                              = Accept;
                socksRequest.Referer                             = Referer;
                socksRequest.AllowAutoRedirect                   = AllowAutoRedirect;
                socksRequest.DnsResolvedBySocksProxy             = DnsResolvedBySocksProxy;
                socksRequest.ValidateServerCertificateSocksProxy = ValidateServerCertificateSocksProxy;
                socksRequest.RefuseOtherDomainRedirect           = RefuseOtherDomainRedirect;
            }

            request.Timeout = (int)Timeout.TotalMilliseconds;
            request.Proxy   = Proxy.ProxyItem;

            return(request);
        }
예제 #6
0
        static string WebMethodSocks(string uri)
        {
            WebRequest req = SocksHttpWebRequest.Create(uri);

            req.Proxy = new WebProxy(new Uri("socks5://192.168.0.231:1080"));
            string res;

            using (WebResponse resp = req.GetResponse())
                using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
                    res = sr.ReadToEnd();

            return(res);
        }
예제 #7
0
        private WebRequest GetRequest(string url)
        {
            WebRequest request = IsSocksProxy ? SocksHttpWebRequest.Create(url) : WebRequest.Create(url);

            if (WebProxy != null)
            {
                request.Proxy = WebProxy;
            }

            if (Credential != null)
            {
                request.PreAuthenticate = true;
                request.Credentials     = Credential;
            }

            if (!string.IsNullOrEmpty(fAuthorization))
            {
                request.Headers.Set("Authorization", fAuthorization);
            }

            if (request is HttpWebRequest)
            {
                var r = request as HttpWebRequest;
                r.UserAgent        = UserAgent;
                r.ReadWriteTimeout = TimeoutMs * 6;
                r.Accept           = RequestAccept;
                r.Referer          = RefererUrl;
                r.Timeout          = TimeoutMs;
            }
            else if (request is SocksHttpWebRequest)
            {
                var r = request as SocksHttpWebRequest;

                if (!string.IsNullOrEmpty(UserAgent))
                {
                    r.Headers.Add("User-Agent", UserAgent);
                }

                if (!string.IsNullOrEmpty(RequestAccept))
                {
                    r.Headers.Add("Accept", RequestAccept);
                }

                if (!string.IsNullOrEmpty(RefererUrl))
                {
                    r.Headers.Add("Referer", RefererUrl);
                }
            }

            return(request);
        }
예제 #8
0
        protected string GetContentUsingHttp(string url)
        {
            string ret = string.Empty;

#if !PocketPC
            WebRequest request = IsSocksProxy ? SocksHttpWebRequest.Create(url) : WebRequest.Create(url);
#else
            WebRequest request = WebRequest.Create(url);
#endif

            if (WebProxy != null)
            {
                request.Proxy = WebProxy;
            }

            if (Credential != null)
            {
                request.PreAuthenticate = true;
                request.Credentials     = Credential;
            }

            if (request is HttpWebRequest)
            {
                var r = request as HttpWebRequest;
                r.UserAgent        = UserAgent;
                r.ReadWriteTimeout = TimeoutMs * 6;
                r.Accept           = requestAccept;
                r.Referer          = RefererUrl;
                r.Timeout          = TimeoutMs;
            }

            using (var response = request.GetResponse())
            {
                using (Stream responseStream = response.GetResponseStream())
                {
                    using (StreamReader read = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        ret = read.ReadToEnd();
                    }
                }
#if PocketPC
                request.Abort();
#endif
                response.Close();
            }

            return(ret);
        }
    protected override WebRequest GetWebRequest(Uri address)
    {
        WebRequest result = null;

        if (ProxyDetails != null)
        {
            if (ProxyDetails.ProxyType == ProxyType.Proxy)
            {
                result       = (HttpWebRequest)WebRequest.Create(address);
                result.Proxy = new WebProxy(ProxyDetails.FullProxyAddress);
                if (!string.IsNullOrEmpty(UserAgent))
                {
                    ((HttpWebRequest)result).UserAgent = UserAgent;
                }
            }
            else if (ProxyDetails.ProxyType == ProxyType.Socks)
            {
                result       = SocksHttpWebRequest.Create(address);
                result.Proxy = new WebProxy(ProxyDetails.FullProxyAddress);
                //TODO: implement user and password
            }
            else if (ProxyDetails.ProxyType == ProxyType.None)
            {
                result = (HttpWebRequest)WebRequest.Create(address);
                if (!string.IsNullOrEmpty(UserAgent))
                {
                    ((HttpWebRequest)result).UserAgent = UserAgent;
                }
            }
        }
        else
        {
            result = (HttpWebRequest)WebRequest.Create(address);
            if (!string.IsNullOrEmpty(UserAgent))
            {
                ((HttpWebRequest)result).UserAgent = UserAgent;
            }
        }


        return(result);
    }
예제 #10
0
        protected override WebRequest GetWebRequest(Uri address)
        {
            WebRequest request = null;

            if (Proxy.ProxyType != ProxyTypeEnum.Socks)
            {
                request = base.GetWebRequest(address);
            }
            else
            {
                request               = SocksHttpWebRequest.Create(address);
                request.Method        = base.GetWebRequest(address).Method;
                request.ContentLength = base.GetWebRequest(address).ContentLength;
                request.ContentType   = base.GetWebRequest(address).ContentType;
            }

            request.Headers.Add("Cookie", Cookies.GetCookieHeader(address));
            request.Headers.Add("Accept-Language", AcceptLanguage);
            request.Headers.Add("Accept-Encoding", AcceptEncoding);


            if (Proxy.ProxyType != ProxyTypeEnum.Socks)
            {
                var httpRequest = (request as HttpWebRequest);
                httpRequest.UserAgent = UserAgent;
                httpRequest.Accept    = Accept;
                httpRequest.Referer   = Referer;
                httpRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
            }
            else if (Proxy.ProxyType == ProxyTypeEnum.Socks)
            {
                var socksRequest = (request as SocksHttpWebRequest);
                socksRequest.UserAgent = UserAgent;
                socksRequest.Accept    = Accept;
                socksRequest.Referer   = Referer;
            }

            request.Timeout = (int)Timeout.TotalMilliseconds;
            request.Proxy   = Proxy.ProxyItem;

            return(request);
        }
예제 #11
0
        protected string GetContentUsingHttp(string url)
        {
            string ret = string.Empty;

            var request = IsSocksProxy ? SocksHttpWebRequest.Create(url) :
                          WebRequestFactory != null?WebRequestFactory(this, url) : WebRequest.Create(url);

            if (WebProxy != null)
            {
                request.Proxy = WebProxy;
            }

            if (Credential != null)
            {
                request.PreAuthenticate = true;
                request.Credentials     = Credential;
            }


            if (!string.IsNullOrEmpty(_authorization))
            {
                request.Headers.Set("Authorization", _authorization);
            }

            if (request is HttpWebRequest r)
            {
                r.UserAgent        = UserAgent;
                r.ReadWriteTimeout = TimeoutMs * 6;
                r.Accept           = requestAccept;
                r.Referer          = RefererUrl;
                r.Timeout          = TimeoutMs;
            }
            else
            {
                if (!string.IsNullOrEmpty(UserAgent))
                {
                    request.Headers.Add("User-Agent", UserAgent);
                }

                if (!string.IsNullOrEmpty(requestAccept))
                {
                    request.Headers.Add("Accept", requestAccept);
                }

                if (!string.IsNullOrEmpty(RefererUrl))
                {
                    request.Headers.Add("Referer", RefererUrl);
                }
            }

            InitializeWebRequest(request);

            WebResponse response;

            try
            {
                response = request.GetResponse();
            }
            catch (WebException ex)
            {
                response = (HttpWebResponse)ex.Response;
            }
            catch (Exception)
            {
                response = null;
            }

            if (response != null)
            {
                using (var responseStream = response.GetResponseStream())
                {
                    using (var read = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        ret = read.ReadToEnd();
                    }
                }

                response.Close();
            }

            return(ret);
        }
예제 #12
0
        protected PureImage GetTileImageUsingHttp(string url)
        {
            PureImage ret = null;

#if !PocketPC
            WebRequest request = IsSocksProxy ? SocksHttpWebRequest.Create(url) : WebRequest.Create(url);
#else
            WebRequest request = WebRequest.Create(url);
#endif
            if (WebProxy != null)
            {
                request.Proxy = WebProxy;
            }

            if (Credential != null)
            {
                request.PreAuthenticate = true;
                request.Credentials     = Credential;
            }

            if (request is HttpWebRequest)
            {
                var r = request as HttpWebRequest;
                r.UserAgent        = UserAgent;
                r.ReadWriteTimeout = TimeoutMs * 6;
                r.Accept           = requestAccept;
                r.Referer          = RefererUrl;
                r.Timeout          = TimeoutMs;
            }
#if !PocketPC
            else if (request is SocksHttpWebRequest)
            {
                var r = request as SocksHttpWebRequest;

                if (!string.IsNullOrEmpty(UserAgent))
                {
                    r.Headers.Add("User-Agent", UserAgent);
                }

                if (!string.IsNullOrEmpty(requestAccept))
                {
                    r.Headers.Add("Accept", requestAccept);
                }

                if (!string.IsNullOrEmpty(RefererUrl))
                {
                    r.Headers.Add("Referer", RefererUrl);
                }
            }
#endif
            using (var response = request.GetResponse())
            {
                if (CheckTileImageHttpResponse(response))
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        MemoryStream data = Stuff.CopyStream(responseStream, false);

                        Debug.WriteLine("Response[" + data.Length + " bytes]: " + url);

                        if (data.Length > 0)
                        {
                            ret = TileImageProxy.FromStream(data);

                            if (ret != null)
                            {
                                ret.Data          = data;
                                ret.Data.Position = 0;
                            }
                            else
                            {
                                data.Dispose();
                            }
                        }
                        data = null;
                    }
                }
                else
                {
                    Debug.WriteLine("CheckTileImageHttpResponse[false]: " + url);
                }
#if PocketPC
                request.Abort();
#endif
                response.Close();
            }
            return(ret);
        }
예제 #13
0
        protected PureImage GetTileImageUsingHttp(string url)
        {
            PureImage ret = null;

            var request = IsSocksProxy ? SocksHttpWebRequest.Create(url) :
                          WebRequestFactory != null?WebRequestFactory(this, url) : WebRequest.Create(url);

            if (WebProxy != null)
            {
                request.Proxy = WebProxy;
            }

            if (Credential != null)
            {
                request.PreAuthenticate = true;
                request.Credentials     = Credential;
            }

            if (!string.IsNullOrEmpty(_authorization))
            {
                request.Headers.Set("Authorization", _authorization);
            }

            if (request is HttpWebRequest r)
            {
                r.UserAgent        = UserAgent;
                r.ReadWriteTimeout = TimeoutMs * 6;
                r.Accept           = requestAccept;
                if (!string.IsNullOrEmpty(RefererUrl))
                {
                    r.Referer = RefererUrl;
                }

                r.Timeout = TimeoutMs;
            }
            else
            {
                if (!string.IsNullOrEmpty(UserAgent))
                {
                    request.Headers.Add("User-Agent", UserAgent);
                }

                if (!string.IsNullOrEmpty(requestAccept))
                {
                    request.Headers.Add("Accept", requestAccept);
                }

                if (!string.IsNullOrEmpty(RefererUrl))
                {
                    request.Headers.Add("Referer", RefererUrl);
                }
            }

            InitializeWebRequest(request);

            using (var response = request.GetResponse())
            {
                if (CheckTileImageHttpResponse(response))
                {
                    using (var responseStream = response.GetResponseStream())
                    {
                        var data = Stuff.CopyStream(responseStream, false);

                        Debug.WriteLine("Response[" + data.Length + " bytes]: " + url);

                        if (data.Length > 0)
                        {
                            ret = TileImageProxy.FromStream(data);

                            if (ret != null)
                            {
                                ret.Data          = data;
                                ret.Data.Position = 0;
                            }
                            else
                            {
                                data.Dispose();
                            }
                        }
                    }
                }
                else
                {
                    Debug.WriteLine("CheckTileImageHttpResponse[false]: " + url);
                }

                response.Close();
            }

            return(ret);
        }
예제 #14
0
        protected PureImage GetTileImageUsingHttp(string url)
        {
            // URLに対するアクセス回数保存用処理ここから
            // 現在日付取得

            DateTime dtNow = DateTime.Now;

            if (dtNow.ToString("yyyy/MM/dd") != strUrlCountDate)
            {
                // 日付が異なる場合
                strUrlCountDate = dtNow.ToString("yyyy/MM/dd");
                dicUrlCount.Clear();
            }

            Uri u = new Uri(url);

            if (dicUrlCount.ContainsKey(u.Host))
            {
                // キーが存在する場合
                int i = dicUrlCount[u.Host];
                i++;
                dicUrlCount[u.Host] = i;
            }
            else
            {
                // キーが存在しない場合
                dicUrlCount[u.Host] = 1;
            }
            // URLに対するアクセス回数保存用処理ここまで

            PureImage ret = null;

#if !PocketPC
            WebRequest request = IsSocksProxy ? SocksHttpWebRequest.Create(url) : WebRequest.Create(url);
#else
            WebRequest request = WebRequest.Create(url);
#endif
            if (WebProxy != null)
            {
                request.Proxy = WebProxy;
            }

            if (Credential != null)
            {
                request.PreAuthenticate = true;
                request.Credentials     = Credential;
            }

            if (request is HttpWebRequest)
            {
                var r = request as HttpWebRequest;
                r.UserAgent        = UserAgent;
                r.ReadWriteTimeout = TimeoutMs * 6;
                r.Accept           = requestAccept;
                r.Referer          = RefererUrl;
                r.Timeout          = TimeoutMs;
            }
#if !PocketPC
            else if (request is SocksHttpWebRequest)
            {
                var r = request as SocksHttpWebRequest;

                if (!string.IsNullOrEmpty(UserAgent))
                {
                    r.Headers.Add("User-Agent", UserAgent);
                }

                if (!string.IsNullOrEmpty(requestAccept))
                {
                    r.Headers.Add("Accept", requestAccept);
                }

                if (!string.IsNullOrEmpty(RefererUrl))
                {
                    r.Headers.Add("Referer", RefererUrl);
                }
            }
#endif
            using (var response = request.GetResponse())
            {
                if (CheckTileImageHttpResponse(response))
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        MemoryStream data = Stuff.CopyStream(responseStream, false);

                        Debug.WriteLine("Response[" + data.Length + " bytes]: " + url);

                        if (data.Length > 0)
                        {
                            ret = TileImageProxy.FromStream(data);

                            if (ret != null)
                            {
                                ret.Data          = data;
                                ret.Data.Position = 0;
                            }
                            else
                            {
                                data.Dispose();
                            }
                        }
                        data = null;
                    }
                }
                else
                {
                    Debug.WriteLine("CheckTileImageHttpResponse[false]: " + url);
                }
#if PocketPC
                request.Abort();
#endif
                response.Close();
            }
            return(ret);
        }
예제 #15
0
        protected string GetContentUsingHttp(string url)
        {
            string ret = string.Empty;

#if !PocketPC
            WebRequest request = IsSocksProxy ? SocksHttpWebRequest.Create(url) : WebRequest.Create(url);
#else
            WebRequest request = WebRequest.Create(url);
#endif

            if (WebProxy != null)
            {
                request.Proxy = WebProxy;
            }

            if (Credential != null)
            {
                request.PreAuthenticate = true;
                request.Credentials     = Credential;
            }


            if (!string.IsNullOrEmpty(Authorization))
            {
                request.Headers.Set("Authorization", Authorization);
            }

            if (request is HttpWebRequest)
            {
                var r = request as HttpWebRequest;
                r.UserAgent        = UserAgent;
                r.ReadWriteTimeout = TimeoutMs * 6;
                r.Accept           = requestAccept;
                r.Referer          = RefererUrl;
                r.Timeout          = TimeoutMs;
            }
#if !PocketPC
            else if (request is SocksHttpWebRequest)
            {
                var r = request as SocksHttpWebRequest;

                if (!string.IsNullOrEmpty(UserAgent))
                {
                    r.Headers.Add("User-Agent", UserAgent);
                }

                if (!string.IsNullOrEmpty(requestAccept))
                {
                    r.Headers.Add("Accept", requestAccept);
                }

                if (!string.IsNullOrEmpty(RefererUrl))
                {
                    r.Headers.Add("Referer", RefererUrl);
                }
            }
#endif
            WebResponse response = null;

            try
            {
                response = request.GetResponse();
            }
            catch (WebException ex)
            {
                response = (HttpWebResponse)ex.Response;
            }
            catch (Exception)
            {
                response = null;
            }

            if (response != null)
            {
                using (Stream responseStream = response.GetResponseStream())
                {
                    using (StreamReader read = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        ret = read.ReadToEnd();
                    }
                }
#if PocketPC
                request.Abort();
#endif
                response.Close();
            }

            return(ret);
        }
예제 #16
0
        protected PureImage GetTileImageUsingHttp(string url)
        {
            PureImage ret = null;

#if !PocketPC
            WebRequest request = IsSocksProxy ? SocksHttpWebRequest.Create(url) : WebRequest.Create(url);
#else
            WebRequest request = WebRequest.Create(url);
#endif
            if (WebProxy != null)
            {
                request.Proxy = WebProxy;
            }

            if (Credential != null)
            {
                request.PreAuthenticate = true;
                request.Credentials     = Credential;
            }

            if (request is HttpWebRequest)
            {
                var r = request as HttpWebRequest;
                r.UserAgent        = UserAgent;
                r.ReadWriteTimeout = TimeoutMs * 6;
                r.Accept           = requestAccept;
                r.Referer          = RefererUrl;
                r.Timeout          = TimeoutMs;
            }

            using (var response = request.GetResponse())
            {
                if (CheckTileImageHttpResponse(response))
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        MemoryStream data = Stuff.CopyStream(responseStream, false);


                        if (data.Length > 0)
                        {
                            ret = TileImageProxy.FromStream(data);

                            if (ret != null)
                            {
                                ret.Data          = data;
                                ret.Data.Position = 0;
                            }
                            else
                            {
                                data.Dispose();
                            }
                        }
                        data = null;
                    }
                }
                else
                {
                }
#if PocketPC
                request.Abort();
#endif
                response.Close();
            }
            return(ret);
        }
예제 #17
0
        protected override WebRequest GetWebRequest(Uri address)
        {
            WebRequest request = null;

            if (Proxy.ProxyType != ProxyTypeEnum.Socks && Proxy.ProxyType != ProxyTypeEnum.Socks4)
            {
                request             = base.GetWebRequest(address);
                request.ContentType = string.IsNullOrEmpty(ContentType) ? base.GetWebRequest(address).ContentType : ContentType;
            }
            else if (Proxy.ProxyType == ProxyTypeEnum.Socks)
            {
                request               = SocksHttpWebRequest.Create(address, IsGetIPFromProxyServer);
                request.Method        = base.GetWebRequest(address).Method;
                request.ContentLength = base.GetWebRequest(address).ContentLength;
                request.ContentType   = string.IsNullOrEmpty(ContentType) ? base.GetWebRequest(address).ContentType : ContentType;
            }
            else if (Proxy.ProxyType == ProxyTypeEnum.Socks4)
            {
                request               = Socks4HttpWebRequest.Create(address);
                request.Method        = base.GetWebRequest(address).Method;
                request.ContentLength = base.GetWebRequest(address).ContentLength;
                request.ContentType   = string.IsNullOrEmpty(ContentType) ? base.GetWebRequest(address).ContentType : ContentType;
            }


            request.Headers.Add("Cookie", Cookies.GetCookieHeader(address));
            request.Headers.Add("Accept-Language", AcceptLanguage);
            request.Headers.Add("Accept-Encoding", AcceptEncoding);
            if (CustomHeaders != null)
            {
                foreach (string key in CustomHeaders.AllKeys)
                {
                    request.Headers.Add(key, CustomHeaders[key]);
                }
            }


            if (Proxy.ProxyType != ProxyTypeEnum.Socks && Proxy.ProxyType != ProxyTypeEnum.Socks4)
            {
                var httpRequest = (request as HttpWebRequest);
                httpRequest.UserAgent = UserAgent;
                httpRequest.Accept    = Accept;
                httpRequest.Referer   = Referer;
                httpRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
                httpRequest.AllowAutoRedirect      = AllowAutoRedirect;
            }
            else if (Proxy.ProxyType == ProxyTypeEnum.Socks)
            {
                var socksRequest = (request as SocksHttpWebRequest);
                socksRequest.UserAgent         = UserAgent;
                socksRequest.Accept            = Accept;
                socksRequest.Referer           = Referer;
                socksRequest.AllowAutoRedirect = AllowAutoRedirect;
            }
            else if (Proxy.ProxyType == ProxyTypeEnum.Socks4)
            {
                var socks4Request = (request as Socks4HttpWebRequest);
                socks4Request.UserAgent         = UserAgent;
                socks4Request.Accept            = Accept;
                socks4Request.Referer           = Referer;
                socks4Request.AllowAutoRedirect = AllowAutoRedirect;
            }

            request.Timeout = (int)Timeout.TotalMilliseconds;
            request.Proxy   = Proxy.ProxyItem;

            return(request);
        }