Ejemplo n.º 1
0
        /// <summary>
        /// 下载图片
        /// </summary>
        /// <param name="reTry">重试:1~9</param>
        public void DownloadImg(string needReferer, int reTry = 0)
        {
            try
            {
                #region 创建请求数据
                reTry = (reTry < 0 ? 0 : reTry) > 9 ? 9 : reTry;
                shc.Add("Accept-Ranges", "bytes");
                shc.Referer                = needReferer;
                shc.ContentType            = SessionHeadersValue.ContentTypeAuto;
                shc.AcceptEncoding         = SessionHeadersValue.AcceptEncodingGzip;
                shc.AutomaticDecompression = DecompressionMethods.GZip;
                string[] requrls =
                {
                    img.PreviewUrl,
                    img.JpegUrl,
                    img.OriginalUrl.Replace(".#ext",             ".jpg"),
                    img.OriginalUrl.Replace(".#ext",             ".png"),
                    img.OriginalUrl.Replace(".#ext",             ".gif"),
                    WebUrlEncode(img.PreviewUrl),
                    WebUrlEncode(img.JpegUrl),
                    WebUrlEncode(img.OriginalUrl.Replace(".#ext",".jpg")),
                    WebUrlEncode(img.OriginalUrl.Replace(".#ext",".png")),
                    WebUrlEncode(img.OriginalUrl.Replace(".#ext",".gif"))
                };

                string         requrl = requrls[reTry];
                HttpWebRequest req    = Sweb.CreateWebRequest(requrl, MainWindow.WebProxy, shc);

                //将请求加入请求组
                Reqs.Add(img.Id, req);
                #endregion

                //异步下载开始
                req.BeginGetResponse(new AsyncCallback(RespCallback), new KeyValuePair <int, HttpWebRequest>(img.Id, req));
            }
            catch (Exception ex)
            {
                Program.Log(ex, "Download sample failed");
                StopLoadImg(img.Id, true, "创建下载失败");
            }
        }
Ejemplo n.º 2
0
 public void AddReq(SkillType skill, Req req)
 {
     //Requirements.Add(skill, req);
     Reqs.Add(skill, req);
 }