コード例 #1
0
        /// <summary>
        /// 抓取页面时使用代理
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        private string DownloadWithProxy(string url)
        {
            try
            {
                for (var i = 0; i < 3; i++)
                {
                    WebProxy webProxy = null;

                    var   service = new ProxyService();
                    Proxy proxy   = service.GetProxy();
                    if (proxy != null)
                    {
                        webProxy = new WebProxy(proxy.Adress + ":" + proxy.Port);
                    }

                    var html = HttpHelper.DownloadHtml(url, webProxy, TimeOut);
                    return(html);
                }
            }
            catch (Exception ex)
            {
            }
            return("");
        }