当前位置: 首页>>代码示例>>C#>>正文


C# IResponse.GetContentType方法代码示例

本文整理汇总了C#中IResponse.GetContentType方法的典型用法代码示例。如果您正苦于以下问题:C# IResponse.GetContentType方法的具体用法?C# IResponse.GetContentType怎么用?C# IResponse.GetContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IResponse的用法示例。


在下文中一共展示了IResponse.GetContentType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateDocumentOptions

        /// <summary>
        /// Creates new document creation options. Selects the source from the
        /// response by potentially using the encoding from the configuration.
        /// </summary>
        /// <param name="response">The response to hand over.</param>
        /// <param name="configuration">The configuration to use.</param>
        public CreateDocumentOptions(IResponse response, IConfiguration configuration)
        {
            var contentType = response.GetContentType(MimeTypeNames.Html);
            var encoding = configuration.DefaultEncoding();
            var charset = contentType.GetParameter(AttributeNames.Charset);

            if (!String.IsNullOrEmpty(charset) && TextEncoding.IsSupported(charset))
                encoding = TextEncoding.Resolve(charset);

            _source = new TextSource(response.Content, encoding);
            _contentType = contentType;
            _response = response;
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:19,代码来源:CreateDocumentOptions.cs

示例2: CreateDocumentOptions

        /// <summary>
        /// Creates a new set of document options from the given response with
        /// the provided configuration.
        /// </summary>
        /// <param name="response">The response to pass on.</param>
        /// <param name="configuration">The configuration to use.</param>
        /// <param name="ancestor">The optional import ancestor.</param>
        public CreateDocumentOptions(IResponse response, IConfiguration configuration, IDocument ancestor = null)
        {
            var contentType = response.GetContentType(MimeTypeNames.Html);
            var charset = contentType.GetParameter(AttributeNames.Charset);
            var source = new TextSource(response.Content, configuration.DefaultEncoding());

            if (!String.IsNullOrEmpty(charset) && TextEncoding.IsSupported(charset))
            {
                source.CurrentEncoding = TextEncoding.Resolve(charset);
            }

            _source = source;
            _contentType = contentType;
            _response = response;
            _ancestor = ancestor;
        }
开发者ID:Wojdav,项目名称:AngleSharp,代码行数:23,代码来源:CreateDocumentOptions.cs

示例3: OpenAsync

        /// <summary>
        /// Opens a new document created from the response asynchronously in
        /// the given context.
        /// </summary>
        /// <param name="context">The browsing context to use.</param>
        /// <param name="response">The response to examine.</param>
        /// <param name="cancel">The cancellation token.</param>
        /// <returns>The task that creates the document.</returns>
        public static Task<IDocument> OpenAsync(this IBrowsingContext context, IResponse response, CancellationToken cancel)
        {
            if (response == null)
                throw new ArgumentNullException("response");

            if (context == null)
                context = BrowsingContext.New();

            var contentType = response.GetContentType(MimeTypes.Html);
            var encoding = context.Configuration.DefaultEncoding();
            var charset = contentType.GetParameter(AttributeNames.Charset);

            if (!String.IsNullOrEmpty(charset) && TextEncoding.IsSupported(charset))
                encoding = TextEncoding.Resolve(charset);

            var source = new TextSource(response.Content, encoding);
            return context.LoadDocumentAsync(response, contentType, source, cancel);
        }
开发者ID:kk9599,项目名称:AngleSharp,代码行数:26,代码来源:BrowsingContextExtensions.cs


注:本文中的IResponse.GetContentType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。