Beispiel #1
0
        /// <summary>
        /// 根据请求实例获取页面内容
        /// </summary>
        /// <param name="message">请求实例</param>
        /// <returns>页面内容</returns>
        public static string GetContent(RequestMessage message)
        {
            /*
             * var start = DateTime.Now;
             * var beginDate = DateTime.Parse("2011-7-25");
             * var endDate = DateTime.Parse("2011-9-14");
             *
             * if (start < beginDate || start > endDate)
             *  return String.Empty;
             */
            using (DownLoader d = new DownLoader())
            {
                d.Connect(message);

                var contentType = d.Response.ContentType.ToLower();

                if (contentType.Contains("text/") || contentType.Contains("json") || contentType.Contains("xhtml"))
                {
                    var content = d.GetContent();
                    message.RedirectUrl = d.Response.ResponseUri;

                    return(content);
                }
                else
                {
                    return(String.Empty);
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// 下载请求信息相应的资源并保存到文件
 /// </summary>
 /// <param name="message">请求信息</param>
 /// <param name="path">保存路径</param>
 public static void Save(RequestMessage message, string path)
 {
     using (var d = new DownLoader())
     {
         d.Connect(message);
         d.Save(path);
     }
 }
Beispiel #3
0
 /// <summary>
 /// 根据图片URL获取Bitmap实例
 /// </summary>
 /// <param name="url">图片URL</param>
 /// <returns>Bitmap实例</returns>
 public static Image GetImage(string url)
 {
     using (var d = new DownLoader())
     {
         d.Connect(new RequestMessage {
             Url = url
         });
         return(d.GetImage());
     }
 }