本文整理汇总了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;
}
示例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;
}
示例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);
}