コード例 #1
0
        public async Task <object> Post(PageInfoRequest request)
        {
            string address = request.Address;

            PageHtmlDownloader.Result result;
            string source;

            PageHtmlDownloader downloader = new PageHtmlDownloader();

            try
            {
                result = await downloader.Download(address);

                if (result == null)
                {
                    return(new { Error = "PageNotAvailable" });
                }
                else
                {
                    source = result.Source;
                }
            }
            catch (UriFormatException)
            {
                return(new { Error = "InvalidAddress" });
            }

            string title = Regex.Match(source, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value;

            FaviconLoader loader = new FaviconLoader();

            FaviconLoader.Result favicon = await loader.Load(result.ResultUri, source);

            return(new { Error = "", Title = title, FaviconUrl = favicon?.FaviconUrl, FaviconData = favicon?.Data, FaviconMime = favicon?.MimeType, ResultUrl = result.ResultUri.ToString().TrimEnd('/') });
        }
コード例 #2
0
        /// <summary>
        /// 获取页面的基本请求
        /// </summary>
        /// <param name="pageId"></param>
        /// <returns></returns>
        private BaseRequest GetPageRequest(int pageId, string pageVersion)
        {
            int timestamp = _pageCacher.GetTimeStampOfPage(pageId);
            //int timestamp = 0;
            string      apitype = JsonApiType.page;
            BaseRequest bj      = this.GetCommonBaseRequest(apitype);
            //string pageVersion = "4";
            PageInfoRequest pagerequeset = new PageInfoRequest(pageId, timestamp, _platForm, pageVersion);

            bj.data = pagerequeset;

            return(bj);
        }